still working on it
This commit is contained in:
47
.phpstorm.meta.php
Normal file
47
.phpstorm.meta.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace PHPSTORM_META {
|
||||
override(\Typecho\Widget::widget(0), map([
|
||||
'' => '@'
|
||||
]));
|
||||
|
||||
exitPoint(\Typecho\Widget\Response::redirect());
|
||||
exitPoint(\Typecho\Widget\Response::throwContent());
|
||||
exitPoint(\Typecho\Widget\Response::throwFile());
|
||||
exitPoint(\Typecho\Widget\Response::throwJson());
|
||||
exitPoint(\Typecho\Widget\Response::throwXml());
|
||||
|
||||
override(\Widget\Options::__get(0), map([
|
||||
'feedUrl' => string,
|
||||
'feedRssUrl' => string,
|
||||
'feedAtomUrl' => string,
|
||||
'commentsFeedUrl' => string,
|
||||
'commentsFeedRssUrl' => string,
|
||||
'commentsFeedAtomUrl' => string,
|
||||
'xmlRpcUrl' => string,
|
||||
'index' => string,
|
||||
'siteUrl' => string,
|
||||
'routingTable' => \ArrayObject::class,
|
||||
'rootUrl' => string,
|
||||
'themeUrl' => string,
|
||||
'pluginUrl' => string,
|
||||
'adminUrl' => string,
|
||||
'loginUrl' => string,
|
||||
'loginAction' => string,
|
||||
'registerUrl' => string,
|
||||
'registerAction' => string,
|
||||
'profileUrl' => string,
|
||||
'logoutUrl' => string,
|
||||
'serverTimezone' => int,
|
||||
'contentType' => string,
|
||||
'software' => string,
|
||||
'version' => string,
|
||||
'markdown' => int,
|
||||
'allowedAttachmentTypes'=> \ArrayObject::class
|
||||
]));
|
||||
|
||||
override(\Typecho\Widget::__get(0), map([
|
||||
'sequence' => int,
|
||||
'length' => int
|
||||
]));
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
include 'common.php';
|
||||
include 'header.php';
|
||||
include 'menu.php';
|
||||
|
||||
$errors = $security->systemCheck();
|
||||
?>
|
||||
|
||||
<div class="main">
|
||||
@@ -12,29 +10,17 @@ $errors = $security->systemCheck();
|
||||
<div class="row typecho-page-main" role="main">
|
||||
<div class="col-mb-12">
|
||||
<div id="typecho-welcome">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<form action="<?php echo \Typecho\Common::url('upgrade.php', $options->adminUrl); ?>" method="get">
|
||||
<h3><?php _e('发现安全问题'); ?></h3>
|
||||
<ul>
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<li class="warning"><?php echo $error; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<p><button class="btn primary" type="submit"><?php _e('解决完毕 »'); ?></button></p>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<form action="<?php echo $security->getTokenUrl(
|
||||
\Typecho\Router::url('do', array('action' => 'upgrade', 'widget' => 'Upgrade'),
|
||||
\Typecho\Common::url('index.php', $options->rootUrl))); ?>" method="post">
|
||||
<h3><?php _e('检测到新版本!'); ?></h3>
|
||||
<ul>
|
||||
<li><?php _e('您已经更新了系统程序, 我们还需要执行一些后续步骤来完成升级'); ?></li>
|
||||
<li><?php _e('此程序将把您的系统从 <strong>%s</strong> 升级到 <strong>%s</strong>', $options->version, \Typecho\Common::VERSION); ?></li>
|
||||
<li><strong class="warning"><?php _e('在升级之前强烈建议先<a href="%s">备份您的数据</a>', \Typecho\Common::url('backup.php', $options->adminUrl)); ?></strong></li>
|
||||
</ul>
|
||||
<p><button class="btn primary" type="submit"><?php _e('完成升级 »'); ?></button></p>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<form action="<?php echo $security->getTokenUrl(
|
||||
\Typecho\Router::url('do', array('action' => 'upgrade', 'widget' => 'Upgrade'),
|
||||
\Typecho\Common::url('index.php', $options->rootUrl))); ?>" method="post">
|
||||
<h3><?php _e('检测到新版本!'); ?></h3>
|
||||
<ul>
|
||||
<li><?php _e('您已经更新了系统程序, 我们还需要执行一些后续步骤来完成升级'); ?></li>
|
||||
<li><?php _e('此程序将把您的系统从 <strong>%s</strong> 升级到 <strong>%s</strong>', $options->version, \Typecho\Common::VERSION); ?></li>
|
||||
<li><strong class="warning"><?php _e('在升级之前强烈建议先<a href="%s">备份您的数据</a>', \Typecho\Common::url('backup.php', $options->adminUrl)); ?></strong></li>
|
||||
</ul>
|
||||
<p><button class="btn primary" type="submit"><?php _e('完成升级 »'); ?></button></p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
15
install.php
15
install.php
@@ -402,12 +402,10 @@ function install_redirect(string $url)
|
||||
|
||||
/**
|
||||
* add common js support
|
||||
*
|
||||
* @throws \Typecho\Exception
|
||||
*/
|
||||
function install_js_support()
|
||||
{
|
||||
$options = \Typecho\Widget::widget('Widget_Options');
|
||||
$options = \Typecho\Widget::widget(\Widget\Options::class);
|
||||
|
||||
?>
|
||||
<div id="success" class="row typecho-page-main hidden">
|
||||
@@ -993,7 +991,7 @@ function install_step_2_perform()
|
||||
*/
|
||||
function install_step_3()
|
||||
{
|
||||
$options = \Typecho\Widget::widget('Widget_Options');
|
||||
$options = \Typecho\Widget::widget(\Widget\Options::class);
|
||||
?>
|
||||
<div class="row typecho-page-main">
|
||||
<div class="col-mb-12 col-tb-8 col-tb-offset-2">
|
||||
@@ -1051,7 +1049,7 @@ function install_step_3_perform()
|
||||
|
||||
$request = \Typecho\Request::getInstance();
|
||||
$defaultPassword = \Typecho\Common::randString(8);
|
||||
$options = \Typecho\Widget::widget('Widget_Options');
|
||||
$options = \Typecho\Widget::widget(\Widget\Options::class);
|
||||
|
||||
if (install_is_cli()) {
|
||||
$config = [
|
||||
@@ -1191,7 +1189,7 @@ function install_step_3_perform()
|
||||
install_success(0, [
|
||||
$config['userName'],
|
||||
$config['userPassword'],
|
||||
\Typecho\Widget::widget('Widget_Security')->getTokenUrl($loginUrl, $request->getReferer()),
|
||||
\Typecho\Widget::widget(\Widget\Security::class)->getTokenUrl($loginUrl, $request->getReferer()),
|
||||
$options->siteUrl
|
||||
]);
|
||||
}
|
||||
@@ -1199,7 +1197,6 @@ function install_step_3_perform()
|
||||
/**
|
||||
* dispatch install action
|
||||
*
|
||||
* @throws \Typecho\Exception
|
||||
*/
|
||||
function install_dispatch()
|
||||
{
|
||||
@@ -1211,8 +1208,8 @@ function install_dispatch()
|
||||
}
|
||||
|
||||
// init default options
|
||||
$options = \Typecho\Widget::widget('Widget_Options', install_get_default_options());
|
||||
\Typecho\Widget::widget('Widget_Init');
|
||||
$options = \Typecho\Widget::widget(\Widget\Options::class, install_get_default_options());
|
||||
\Typecho\Widget::widget(\Widget\Init::class);
|
||||
|
||||
// install finished yet
|
||||
if (
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<div class="col-mb-12">
|
||||
<nav id="nav-menu" class="clearfix" role="navigation">
|
||||
<a<?php if($this->is('index')): ?> class="current"<?php endif; ?> href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a>
|
||||
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
|
||||
<?php self::widget('Widget_Contents_Page_List')->to($pages); ?>
|
||||
<?php while($pages->next()): ?>
|
||||
<a<?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a>
|
||||
<?php endwhile; ?>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<section class="widget">
|
||||
<h3 class="widget-title"><?php _e('最新文章'); ?></h3>
|
||||
<ul class="widget-list">
|
||||
<?php $this->widget('Widget_Contents_Post_Recent')
|
||||
<?php self::widget('Widget_Contents_Post_Recent')
|
||||
->parse('<li><a href="{permalink}">{title}</a></li>'); ?>
|
||||
</ul>
|
||||
</section>
|
||||
@@ -14,7 +14,7 @@
|
||||
<section class="widget">
|
||||
<h3 class="widget-title"><?php _e('最近回复'); ?></h3>
|
||||
<ul class="widget-list">
|
||||
<?php $this->widget('Widget_Comments_Recent')->to($comments); ?>
|
||||
<?php self::widget('Widget_Comments_Recent')->to($comments); ?>
|
||||
<?php while($comments->next()): ?>
|
||||
<li><a href="<?php $comments->permalink(); ?>"><?php $comments->author(false); ?></a>: <?php $comments->excerpt(35, '...'); ?></li>
|
||||
<?php endwhile; ?>
|
||||
@@ -25,7 +25,7 @@
|
||||
<?php if (!empty($this->options->sidebarBlock) && in_array('ShowCategory', $this->options->sidebarBlock)): ?>
|
||||
<section class="widget">
|
||||
<h3 class="widget-title"><?php _e('分类'); ?></h3>
|
||||
<?php $this->widget('Widget_Metas_Category_List')->listCategories('wrapClass=widget-list'); ?>
|
||||
<?php self::widget('Widget_Metas_Category_List')->listCategories('wrapClass=widget-list'); ?>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<section class="widget">
|
||||
<h3 class="widget-title"><?php _e('归档'); ?></h3>
|
||||
<ul class="widget-list">
|
||||
<?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=F Y')
|
||||
<?php self::widget('Widget_Contents_Post_Date', 'type=month&format=F Y')
|
||||
->parse('<li><a href="{permalink}">{date}</a></li>'); ?>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
@@ -95,7 +95,7 @@ class Client
|
||||
* @param string|null $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function construct(
|
||||
public function __construct(
|
||||
string $server,
|
||||
?string $path = null,
|
||||
int $port = 80,
|
||||
@@ -201,7 +201,7 @@ class Client
|
||||
* @param string $prefix 前缀
|
||||
* @return Client
|
||||
*/
|
||||
public function get(string $prefix): Client
|
||||
public function __get(string $prefix): Client
|
||||
{
|
||||
return new self($this->server, $this->path, $this->port, $this->useragent, $this->prefix . $prefix . '.');
|
||||
}
|
||||
|
||||
@@ -277,6 +277,15 @@ EOF;
|
||||
return array_column($value, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @return string
|
||||
*/
|
||||
public static function nativeClassName(string $className): string
|
||||
{
|
||||
return trim(str_replace('\\', '_', $className), '_');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据count数目来输出字符
|
||||
* <code>
|
||||
|
||||
@@ -72,7 +72,7 @@ class Plugin
|
||||
public function __construct(string $handle)
|
||||
{
|
||||
/** 初始化变量 */
|
||||
$this->handle = $handle;
|
||||
$this->handle = Common::nativeClassName($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,6 +102,7 @@ class Plugin
|
||||
*/
|
||||
public static function factory(string $handle): Plugin
|
||||
{
|
||||
$handle = Common::nativeClassName($handle);
|
||||
return self::$instances[$handle] ?? (self::$instances[$handle] = new self($handle));
|
||||
}
|
||||
|
||||
@@ -274,6 +275,7 @@ class Plugin
|
||||
$string = strtolower($token[1]);
|
||||
switch ($string) {
|
||||
case 'typecho_plugin_interface':
|
||||
case 'plugininterface':
|
||||
$isInClass = $isClass;
|
||||
break;
|
||||
case 'activate':
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Typecho;
|
||||
|
||||
use Typecho\Widget\Exception as WidgetException;
|
||||
use Typecho\Widget\Helper\EmptyClass;
|
||||
use Typecho\Widget\Request as WidgetRequest;
|
||||
use Typecho\Widget\Response as WidgetResponse;
|
||||
@@ -84,10 +83,10 @@ abstract class Widget
|
||||
* @access public
|
||||
*
|
||||
* @param WidgetRequest $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param WidgetResponse $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
*/
|
||||
public function __construct(WidgetRequest $request, $response, $params = null)
|
||||
public function __construct(WidgetRequest $request, WidgetResponse $response, $params = null)
|
||||
{
|
||||
//设置函数内部对象
|
||||
$this->request = $request;
|
||||
@@ -113,15 +112,11 @@ abstract class Widget
|
||||
/**
|
||||
* 工厂方法,将类静态化放置到列表中
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $alias 组件别名
|
||||
* @param class-string $alias 组件别名
|
||||
* @param mixed $params 传递的参数
|
||||
* @param mixed $request 前端参数
|
||||
* @param boolean $enableResponse 是否允许http回执
|
||||
*
|
||||
* @return Widget
|
||||
* @throws WidgetException
|
||||
*/
|
||||
public static function widget(
|
||||
string $alias,
|
||||
@@ -129,34 +124,28 @@ abstract class Widget
|
||||
$request = null,
|
||||
bool $enableResponse = true
|
||||
): Widget {
|
||||
$parts = explode('@', $alias);
|
||||
$className = $parts[0];
|
||||
$alias = empty($parts[1]) ? $className : $parts[1];
|
||||
[$className] = explode('@', $alias);
|
||||
$key = Common::nativeClassName($alias);
|
||||
|
||||
if (isset(self::$widgetAlias[$className])) {
|
||||
$className = self::$widgetAlias[$className];
|
||||
}
|
||||
|
||||
if (!isset(self::$widgetPool[$alias])) {
|
||||
/** 如果类不存在 */
|
||||
if (!class_exists($className)) {
|
||||
throw new WidgetException($className);
|
||||
}
|
||||
|
||||
if (!isset(self::$widgetPool[$key])) {
|
||||
/** 初始化request */
|
||||
$requestObject = new WidgetRequest(Request::getInstance(), Config::factory($request));
|
||||
|
||||
/** 初始化response */
|
||||
$responseObject = new WidgetResponse(Request::getInstance(), Response::getInstance());
|
||||
$responseObject = new WidgetResponse(Request::getInstance(), Response::getInstance(), $enableResponse);
|
||||
|
||||
/** 初始化组件 */
|
||||
$widget = new $className($requestObject, $responseObject, $params);
|
||||
|
||||
$widget->execute();
|
||||
self::$widgetPool[$alias] = $widget;
|
||||
self::$widgetPool[$key] = $widget;
|
||||
}
|
||||
|
||||
return self::$widgetPool[$alias];
|
||||
return self::$widgetPool[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,7 +253,6 @@ abstract class Widget
|
||||
* 将每一行的值压入堆栈
|
||||
*
|
||||
* @param array $value 每一行的值
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function push(array $value)
|
||||
@@ -331,7 +319,7 @@ abstract class Widget
|
||||
*/
|
||||
public function pluginHandle(?string $handle = null): Plugin
|
||||
{
|
||||
return Plugin::factory(empty($handle) ? get_class($this) : $handle);
|
||||
return Plugin::factory(empty($handle) ? static::class : $handle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,14 +21,21 @@ class Response
|
||||
*/
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $enabled;
|
||||
|
||||
/**
|
||||
* @param HttpRequest $request
|
||||
* @param HttpResponse $response
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function __construct(HttpRequest $request, HttpResponse $response)
|
||||
public function __construct(HttpRequest $request, HttpResponse $response, bool $enabled = true)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +44,9 @@ class Response
|
||||
*/
|
||||
public function setStatus(int $code): Response
|
||||
{
|
||||
$this->response->setStatus($code);
|
||||
if ($this->enabled) {
|
||||
$this->response->setStatus($code);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -48,7 +57,9 @@ class Response
|
||||
*/
|
||||
public function setHeader(string $name, $value): Response
|
||||
{
|
||||
$this->response->setHeader($name, (string) $value);
|
||||
if ($this->enabled) {
|
||||
$this->response->setHeader($name, (string)$value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -60,7 +71,9 @@ class Response
|
||||
*/
|
||||
public function setCharset(string $charset): Response
|
||||
{
|
||||
$this->response->setCharset($charset);
|
||||
if ($this->enabled) {
|
||||
$this->response->setCharset($charset);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -70,7 +83,9 @@ class Response
|
||||
*/
|
||||
public function setContentType(string $contentType = 'text/html'): Response
|
||||
{
|
||||
$this->response->setContentType($contentType);
|
||||
if ($this->enabled) {
|
||||
$this->response->setContentType($contentType);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -80,6 +95,10 @@ class Response
|
||||
*/
|
||||
public function throwContent(string $content, string $contentType = 'text/html')
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->setContentType($contentType)
|
||||
->addResponder(function () use ($content) {
|
||||
echo $content;
|
||||
@@ -92,6 +111,10 @@ class Response
|
||||
*/
|
||||
public function throwXml(string $message)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->setContentType('text/xml')
|
||||
->addResponder(function () use ($message) {
|
||||
echo '<?xml version="1.0" encoding="' . $this->response->getCharset() . '"?>',
|
||||
@@ -109,6 +132,10 @@ class Response
|
||||
*/
|
||||
public function throwJson($message)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** 设置http头信息 */
|
||||
$this->response->setContentType('application/json')
|
||||
->addResponder(function () use ($message) {
|
||||
@@ -123,6 +150,10 @@ class Response
|
||||
*/
|
||||
public function throwFile($file, ?string $contentType = null)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($contentType)) {
|
||||
$this->response->setContentType($contentType);
|
||||
}
|
||||
@@ -142,6 +173,10 @@ class Response
|
||||
*/
|
||||
public function redirect(string $location, bool $isPermanently = false)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$location = Common::safeUrl($location);
|
||||
|
||||
$this->response->setStatus($isPermanently ? 301 : 302)
|
||||
@@ -157,6 +192,10 @@ class Response
|
||||
*/
|
||||
public function goBack(string $suffix = null, string $default = null)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
//获取来源
|
||||
$referer = $this->request->getReferer();
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 异步调用组件
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget;
|
||||
|
||||
use Typecho\Http\Client;
|
||||
use Typecho\Widget\Exception;
|
||||
use Widget\Base\Options as BaseOptions;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步调用组件
|
||||
@@ -17,7 +17,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
*/
|
||||
class Widget_Ajax extends Widget_Abstract_Options implements Widget_Interface_Do
|
||||
class Ajax extends BaseOptions implements DoInterface
|
||||
{
|
||||
/**
|
||||
* 针对rewrite验证的请求返回
|
||||
@@ -35,12 +35,12 @@ class Widget_Ajax extends Widget_Abstract_Options implements Widget_Interface_Do
|
||||
/**
|
||||
* 获取最新版本
|
||||
*
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @throws Exception|\Typecho\Db\Exception
|
||||
*/
|
||||
public function checkVersion()
|
||||
{
|
||||
$this->user->pass('editor');
|
||||
$client = Typecho_Http_Client::get();
|
||||
$client = Client::get();
|
||||
if ($client) {
|
||||
$client->setHeader('User-Agent', $this->options->generator)
|
||||
->setTimeout(10);
|
||||
@@ -57,11 +57,13 @@ class Widget_Ajax extends Widget_Abstract_Options implements Widget_Interface_Do
|
||||
[$soft, $version] = explode(' ', $this->options->generator);
|
||||
$current = explode('/', $version);
|
||||
|
||||
if (isset($json['release']) && isset($json['version'])
|
||||
if (
|
||||
isset($json['release']) && isset($json['version'])
|
||||
&& preg_match("/^[0-9\.]+$/", $json['release'])
|
||||
&& preg_match("/^[0-9\.]+$/", $json['version'])
|
||||
&& version_compare($json['release'], $current[0], '>=')
|
||||
&& version_compare($json['version'], $current[1], '>')) {
|
||||
&& version_compare($json['version'], $current[1], '>')
|
||||
) {
|
||||
$result = [
|
||||
'available' => 1,
|
||||
'latest' => $json['release'] . '-' . $json['version'],
|
||||
@@ -70,26 +72,26 @@ class Widget_Ajax extends Widget_Abstract_Options implements Widget_Interface_Do
|
||||
];
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
$this->response->throwJson($result);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Typecho_Widget_Exception(_t('禁止访问'), 403);
|
||||
throw new Exception(_t('禁止访问'), 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程请求代理
|
||||
*
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @throws Exception
|
||||
* @throws Client\Exception|\Typecho\Db\Exception
|
||||
*/
|
||||
public function feed()
|
||||
{
|
||||
$this->user->pass('subscriber');
|
||||
$client = Typecho_Http_Client::get();
|
||||
$client = Client::get();
|
||||
if ($client) {
|
||||
$client->setHeader('User-Agent', $this->options->generator)
|
||||
->setTimeout(10)
|
||||
@@ -97,7 +99,11 @@ class Widget_Ajax extends Widget_Abstract_Options implements Widget_Interface_Do
|
||||
|
||||
/** 匹配内容体 */
|
||||
$response = $client->getResponseBody();
|
||||
preg_match_all("/<item>\s*<title>([^>]*)<\/title>\s*<link>([^>]*)<\/link>\s*<guid>[^>]*<\/guid>\s*<pubDate>([^>]*)<\/pubDate>/is", $response, $matches);
|
||||
preg_match_all(
|
||||
"/<item>\s*<title>([^>]*)<\/title>\s*<link>([^>]*)<\/link>\s*<guid>[^>]*<\/guid>\s*<pubDate>([^>]*)<\/pubDate>/is",
|
||||
$response,
|
||||
$matches
|
||||
);
|
||||
|
||||
$data = [];
|
||||
|
||||
@@ -116,27 +122,29 @@ class Widget_Ajax extends Widget_Abstract_Options implements Widget_Interface_Do
|
||||
}
|
||||
|
||||
$this->response->throwJson($data);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Typecho_Widget_Exception(_t('禁止访问'), 403);
|
||||
throw new Exception(_t('禁止访问'), 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义编辑器大小
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws \Typecho\Db\Exception|Exception
|
||||
*/
|
||||
public function editorResize()
|
||||
{
|
||||
$this->user->pass('contributor');
|
||||
if ($this->db->fetchObject($this->db->select(['COUNT(*)' => 'num'])
|
||||
->from('table.options')->where('name = ? AND user = ?', 'editorSize', $this->user->uid))->num > 0) {
|
||||
$this->widget('Widget_Abstract_Options')
|
||||
->update(['value' => $this->request->size], $this->db->sql()->where('name = ? AND user = ?', 'editorSize', $this->user->uid));
|
||||
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],
|
||||
$this->db->sql()->where('name = ? AND user = ?', 'editorSize', $this->user->uid)
|
||||
);
|
||||
} else {
|
||||
$this->widget('Widget_Abstract_Options')->insert([
|
||||
parent::insert([
|
||||
'name' => 'editorSize',
|
||||
'value' => $this->request->size,
|
||||
'user' => $this->user->uid
|
||||
|
||||
@@ -12,8 +12,13 @@ use Typecho\Widget\Exception as WidgetException;
|
||||
use Typecho\Widget\Helper\PageNavigator;
|
||||
use Typecho\Widget\Helper\PageNavigator\Classic;
|
||||
use Typecho\Widget\Helper\PageNavigator\Box;
|
||||
use Widget\Base\Comments;
|
||||
use Widget\Base\Contents;
|
||||
use Widget\Base\Metas;
|
||||
use Widget\Base\Users;
|
||||
use Widget\Comments\Ping;
|
||||
use Widget\Comments\Recent;
|
||||
use Widget\Contents\Attachment\Related;
|
||||
use Widget\Metas\Category\Rows;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
@@ -878,10 +883,9 @@ class Archive extends Contents
|
||||
* 获取评论归档对象
|
||||
*
|
||||
* @access public
|
||||
* @return Comments
|
||||
* @throws WidgetException
|
||||
* @return \Widget\Comments\Archive
|
||||
*/
|
||||
public function comments(): Comments
|
||||
public function comments(): \Widget\Comments\Archive
|
||||
{
|
||||
$parameter = [
|
||||
'parentId' => $this->hidden ? 0 : $this->cid,
|
||||
@@ -891,19 +895,17 @@ class Archive extends Contents
|
||||
'allowComment' => $this->allow('comment')
|
||||
];
|
||||
|
||||
return $this->widget('\Widget\Comments\Archive', $parameter);
|
||||
return self::widget(\Widget\Comments\Archive::class, $parameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取回响归档对象
|
||||
*
|
||||
* @access public
|
||||
* @return Comments
|
||||
* @throws WidgetException
|
||||
* @return Ping
|
||||
*/
|
||||
public function pings(): Comments
|
||||
public function pings(): Ping
|
||||
{
|
||||
return $this->widget('\Widget\Comments\Ping', [
|
||||
return self::widget(Ping::class, [
|
||||
'parentId' => $this->hidden ? 0 : $this->cid,
|
||||
'parentContent' => $this->row,
|
||||
'allowPing' => $this->allow('ping')
|
||||
@@ -913,14 +915,13 @@ class Archive extends Contents
|
||||
/**
|
||||
* 获取附件对象
|
||||
*
|
||||
* @access public
|
||||
* @param integer $limit 最大个数
|
||||
* @param integer $offset 重新
|
||||
* @return Widget_Contents_Attachment_Related
|
||||
* @return Related
|
||||
*/
|
||||
public function attachments($limit = 0, $offset = 0)
|
||||
public function attachments(int $limit = 0, int $offset = 0): Related
|
||||
{
|
||||
return $this->widget('\Widget\Contents\Attachment\Related@' . $this->cid . '-' . uniqid(), [
|
||||
return self::widget(Related::class . '@' . $this->cid . '-' . uniqid(), [
|
||||
'parentId' => $this->cid,
|
||||
'limit' => $limit,
|
||||
'offset' => $offset
|
||||
@@ -930,13 +931,11 @@ class Archive extends Contents
|
||||
/**
|
||||
* 显示下一个内容的标题链接
|
||||
*
|
||||
* @access public
|
||||
* @param string $format 格式
|
||||
* @param string $default 如果没有下一篇,显示的默认文字
|
||||
* @param string|null $default 如果没有下一篇,显示的默认文字
|
||||
* @param array $custom 定制化样式
|
||||
* @return void
|
||||
*/
|
||||
public function theNext($format = '%s', $default = null, $custom = [])
|
||||
public function theNext(string $format = '%s', ?string $default = null, array $custom = [])
|
||||
{
|
||||
$content = $this->db->fetchRow($this->select()->where(
|
||||
'table.contents.created > ? AND table.contents.created < ?',
|
||||
@@ -960,7 +959,8 @@ class Archive extends Contents
|
||||
|
||||
$linkText = empty($title) ? $content['title'] : $title;
|
||||
$linkClass = empty($tagClass) ? '' : 'class="' . $tagClass . '" ';
|
||||
$link = '<a ' . $linkClass . 'href="' . $content['permalink'] . '" title="' . $content['title'] . '">' . $linkText . '</a>';
|
||||
$link = '<a ' . $linkClass . 'href="' . $content['permalink']
|
||||
. '" title="' . $content['title'] . '">' . $linkText . '</a>';
|
||||
|
||||
printf($format, $link);
|
||||
} else {
|
||||
@@ -1019,13 +1019,13 @@ class Archive extends Contents
|
||||
switch ($type) {
|
||||
case 'author':
|
||||
/** 如果访问权限被设置为禁止,则tag会被置为空 */
|
||||
return $this->widget(
|
||||
return self::widget(
|
||||
'\Widget\Contents\Related\Author',
|
||||
['cid' => $this->cid, 'type' => $this->type, 'author' => $this->author->uid, 'limit' => $limit]
|
||||
);
|
||||
default:
|
||||
/** 如果访问权限被设置为禁止,则tag会被置为空 */
|
||||
return $this->widget(
|
||||
return self::widget(
|
||||
'\Widget\Contents\Related',
|
||||
['cid' => $this->cid, 'type' => $this->type, 'tags' => $this->tags, 'limit' => $limit]
|
||||
);
|
||||
@@ -1429,9 +1429,9 @@ class Archive extends Contents
|
||||
));
|
||||
|
||||
if ('comments' == $this->parameter->type) {
|
||||
$comments = $this->widget('\Widget\Comments\Recent', 'pageSize=10');
|
||||
$comments = self::widget(Recent::class, 'pageSize=10');
|
||||
} else {
|
||||
$comments = $this->widget('\Widget\Comments\Recent', 'pageSize=10&parentId=' . $this->cid);
|
||||
$comments = self::widget(Recent::class, 'pageSize=10&parentId=' . $this->cid);
|
||||
}
|
||||
|
||||
while ($comments->next()) {
|
||||
@@ -1811,7 +1811,7 @@ class Archive extends Contents
|
||||
$this->keywords = implode(',', array_column($this->tags, 'name'));
|
||||
|
||||
/** 设置描述 */
|
||||
$this->description = $this->row['description'];
|
||||
$this->description = $this->___description();
|
||||
}
|
||||
|
||||
/** 设置归档类型 */
|
||||
@@ -1866,7 +1866,7 @@ class Archive extends Contents
|
||||
throw new WidgetException(_t('分类不存在'), 404);
|
||||
}
|
||||
|
||||
$categoryListWidget = $this->widget('\Widget\Metas\Category\List', 'current=' . $category['mid']);
|
||||
$categoryListWidget = self::widget(Rows::class, 'current=' . $category['mid']);
|
||||
$category = $categoryListWidget->filter($category);
|
||||
|
||||
if (isset($directory) && ($this->request->directory != implode('/', $category['directory']))) {
|
||||
@@ -1942,7 +1942,7 @@ class Archive extends Contents
|
||||
/** 如果是标签 */
|
||||
$tag = $this->db->fetchRow(
|
||||
$tagSelect,
|
||||
[$this->widget('\Widget\Abstract\Metas'), 'filter']
|
||||
[self::widget(Metas::class), 'filter']
|
||||
);
|
||||
|
||||
if (!$tag) {
|
||||
@@ -2004,7 +2004,7 @@ class Archive extends Contents
|
||||
$author = $this->db->fetchRow(
|
||||
$this->db->select()->from('table.users')
|
||||
->where('uid = ?', $uid),
|
||||
[$this->widget('\Widget\Abstract\Users'), 'filter']
|
||||
[self::widget(Users::class), 'filter']
|
||||
);
|
||||
|
||||
if (!$author) {
|
||||
|
||||
@@ -184,19 +184,19 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_
|
||||
if (0 == $file['error'] && is_uploaded_file($file['tmp_name'])) {
|
||||
$path = $file['tmp_name'];
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t('备份文件上传失败'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('备份文件上传失败'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
} else {
|
||||
if (!$this->request->is('file')) {
|
||||
$this->widget('Widget_Notice')->set(_t('没有选择任何备份文件'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('没有选择任何备份文件'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
$path = __TYPECHO_BACKUP_DIR__ . '/' . $this->request->get('file');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
$this->widget('Widget_Notice')->set(_t('备份文件不存在'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('备份文件不存在'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_
|
||||
$fp = @fopen($file, 'rb');
|
||||
|
||||
if (!$fp) {
|
||||
$this->widget('Widget_Notice')->set(_t('无法读取备份文件'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('无法读取备份文件'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_
|
||||
|
||||
if ($fileSize < $headerSize) {
|
||||
@fclose($fp);
|
||||
$this->widget('Widget_Notice')->set(_t('备份文件格式错误'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('备份文件格式错误'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_
|
||||
|
||||
if (!$this->parseHeader($fileHeader, $version)) {
|
||||
@fclose($fp);
|
||||
$this->widget('Widget_Notice')->set(_t('备份文件格式错误'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('备份文件格式错误'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_
|
||||
|
||||
if (!$this->parseHeader($fileFooter, $version)) {
|
||||
@fclose($fp);
|
||||
$this->widget('Widget_Notice')->set(_t('备份文件格式错误'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('备份文件格式错误'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_
|
||||
|
||||
if (!$data) {
|
||||
@fclose($fp);
|
||||
$this->widget('Widget_Notice')->set(_t('恢复数据出现错误'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('恢复数据出现错误'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_
|
||||
}
|
||||
|
||||
@fclose($fp);
|
||||
$this->widget('Widget_Notice')->set(_t('数据恢复完成'), 'success');
|
||||
self::widget('Widget_Notice')->set(_t('数据恢复完成'), 'success');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_
|
||||
|
||||
$db->query($db->insert('table.' . $table)->rows($this->applyFields($table, $data)));
|
||||
} catch (Exception $e) {
|
||||
$this->widget('Widget_Notice')->set(_t('恢复过程中遇到如下错误: %s', $e->getMessage()), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('恢复过程中遇到如下错误: %s', $e->getMessage()), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,23 +23,21 @@ abstract class Base extends Widget
|
||||
/**
|
||||
* 全局选项
|
||||
*
|
||||
* @access protected
|
||||
* @var Widget_Options
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* 用户对象
|
||||
*
|
||||
* @access protected
|
||||
* @var Widget_User
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* 安全模块
|
||||
*
|
||||
* @var Widget_Security
|
||||
* @var Security
|
||||
*/
|
||||
protected $security;
|
||||
|
||||
@@ -57,7 +55,7 @@ abstract class Base extends Widget
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @throws Db\Exception|Widget\Exception
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
{
|
||||
@@ -67,9 +65,9 @@ abstract class Base extends Widget
|
||||
$this->db = Db::get();
|
||||
|
||||
/** 初始化常用组件 */
|
||||
$this->options = $this->widget('Widget_Options');
|
||||
$this->user = $this->widget('Widget_User');
|
||||
$this->security = $this->widget('Widget_Security');
|
||||
$this->options = self::widget('Widget_Options');
|
||||
$this->user = self::widget('Widget_User');
|
||||
$this->security = self::widget('Widget_Security');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -286,9 +286,9 @@ class Comments extends Base
|
||||
*/
|
||||
protected function ___parentContent(): ?array
|
||||
{
|
||||
return $this->db->fetchRow($this->widget('Widget_Abstract_Contents')->select()
|
||||
return $this->db->fetchRow(self::widget(Contents::class)->select()
|
||||
->where('table.contents.cid = ?', $this->cid)
|
||||
->limit(1), [$this->widget('Widget_Abstract_Contents'), 'filter']);
|
||||
->limit(1), [self::widget(Contents::class), 'filter']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,8 @@ use Typecho\Plugin;
|
||||
use Typecho\Router;
|
||||
use Typecho\Widget;
|
||||
use Widget\Base;
|
||||
use Widget\Metas\Category\Rows;
|
||||
use Widget\User\Author;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
@@ -445,7 +447,7 @@ class Contents extends Base
|
||||
->select()->from('table.metas')
|
||||
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
|
||||
->where('table.relationships.cid = ?', $value['cid'])
|
||||
->where('table.metas.type = ?', 'category'), [$this->widget('Widget_Metas_Category_List'), 'filter']);
|
||||
->where('table.metas.type = ?', 'category'), [self::widget(Rows::class), 'filter']);
|
||||
|
||||
$value['category'] = null;
|
||||
$value['directory'] = [];
|
||||
@@ -464,7 +466,7 @@ class Contents extends Base
|
||||
|
||||
$value['category'] = $value['categories'][0]['slug'];
|
||||
|
||||
$value['directory'] = $this->widget('Widget_Metas_Category_List')
|
||||
$value['directory'] = self::widget(Rows::class)
|
||||
->getAllParentsSlug($value['categories'][0]['mid']);
|
||||
$value['directory'][] = $value['category'];
|
||||
}
|
||||
@@ -698,7 +700,7 @@ class Contents extends Base
|
||||
public function directory(string $split = '/', bool $link = true, ?string $default = null)
|
||||
{
|
||||
$category = $this->categories[0];
|
||||
$directory = $this->widget('Widget_Metas_Category_List')->getAllParents($category['mid']);
|
||||
$directory = self::widget(Rows::class)->getAllParents($category['mid']);
|
||||
$directory[] = $category;
|
||||
|
||||
if ($directory) {
|
||||
@@ -752,7 +754,7 @@ class Contents extends Base
|
||||
* 将tags取出
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception|Widget\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function ___tags(): array
|
||||
{
|
||||
@@ -760,18 +762,17 @@ class Contents extends Base
|
||||
->select()->from('table.metas')
|
||||
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
|
||||
->where('table.relationships.cid = ?', $this->cid)
|
||||
->where('table.metas.type = ?', 'tag'), [$this->widget('Widget_Abstract_Metas'), 'filter']);
|
||||
->where('table.metas.type = ?', 'tag'), [self::widget(Metas::class), 'filter']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章作者
|
||||
*
|
||||
* @return Widget
|
||||
* @throws Widget\Exception
|
||||
*/
|
||||
protected function ___author(): Widget
|
||||
{
|
||||
return $this->widget('Widget_Users_Author@' . $this->cid, ['uid' => $this->authorId]);
|
||||
return self::widget(Author::class . '@' . $this->cid, ['uid' => $this->authorId]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -191,10 +191,10 @@ class Metas extends Base
|
||||
* 根据tag获取ID
|
||||
*
|
||||
* @param mixed $inputTags 标签名
|
||||
* @return array
|
||||
* @return array|int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function scanTags($inputTags): array
|
||||
public function scanTags($inputTags)
|
||||
{
|
||||
$tags = is_array($inputTags) ? $inputTags : [$inputTags];
|
||||
$result = [];
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* Typecho Blog Platform
|
||||
*
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Comments;
|
||||
|
||||
use Typecho\Cookie;
|
||||
use Typecho\Db;
|
||||
use Typecho\Db\Query;
|
||||
use Typecho\Widget\Exception;
|
||||
use Typecho\Widget\Helper\PageNavigator\Box;
|
||||
use Widget\Base\Comments;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台评论输出组件
|
||||
@@ -17,15 +23,15 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Comments_Admin extends Widget_Abstract_Comments
|
||||
class Admin extends Comments
|
||||
{
|
||||
/**
|
||||
* 分页计算对象
|
||||
*
|
||||
* @access private
|
||||
* @var Typecho_Db_Query
|
||||
* @var Query
|
||||
*/
|
||||
private $_countSql;
|
||||
private $countSql;
|
||||
|
||||
/**
|
||||
* 当前页
|
||||
@@ -33,7 +39,7 @@ class Widget_Comments_Admin extends Widget_Abstract_Comments
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_currentPage;
|
||||
private $currentPage;
|
||||
|
||||
/**
|
||||
* 所有文章个数
|
||||
@@ -41,15 +47,15 @@ class Widget_Comments_Admin extends Widget_Abstract_Comments
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_total = false;
|
||||
private $total = false;
|
||||
|
||||
/**
|
||||
* 获取菜单标题
|
||||
*
|
||||
* @return string
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getMenuTitle()
|
||||
public function getMenuTitle(): string
|
||||
{
|
||||
$content = $this->parentContent;
|
||||
|
||||
@@ -57,20 +63,19 @@ class Widget_Comments_Admin extends Widget_Abstract_Comments
|
||||
return _t('%s的评论', $content['title']);
|
||||
}
|
||||
|
||||
throw new Typecho_Widget_Exception(_t('内容不存在'), 404);
|
||||
throw new Exception(_t('内容不存在'), 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception|Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$select = $this->select();
|
||||
$this->parameter->setDefault('pageSize=20');
|
||||
$this->_currentPage = $this->request->get('page', 1);
|
||||
$this->currentPage = $this->request->get('page', 1);
|
||||
|
||||
/** 过滤标题 */
|
||||
if (null != ($keywords = $this->request->filter('search')->keywords)) {
|
||||
@@ -81,14 +86,14 @@ class Widget_Comments_Admin extends Widget_Abstract_Comments
|
||||
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) {
|
||||
Typecho_Cookie::set('__typecho_all_comments', 'on');
|
||||
if ('on' == $this->request->_typecho_all_comments) {
|
||||
Cookie::set('__typecho_all_comments', 'on');
|
||||
} else {
|
||||
if ('off' == $this->request->__typecho_all_comments) {
|
||||
Typecho_Cookie::set('__typecho_all_comments', 'off');
|
||||
if ('off' == $this->request->_typecho_all_comments) {
|
||||
Cookie::set('__typecho_all_comments', 'off');
|
||||
}
|
||||
|
||||
if ('on' != Typecho_Cookie::get('__typecho_all_comments')) {
|
||||
if ('on' != Cookie::get('__typecho_all_comments')) {
|
||||
$select->where('table.comments.ownerId = ?', $this->user->uid);
|
||||
}
|
||||
}
|
||||
@@ -107,10 +112,10 @@ class Widget_Comments_Admin extends Widget_Abstract_Comments
|
||||
$select->where('table.comments.cid = ?', $this->request->filter('int')->cid);
|
||||
}
|
||||
|
||||
$this->_countSql = clone $select;
|
||||
$this->countSql = clone $select;
|
||||
|
||||
$select->order('table.comments.coid', Typecho_Db::SORT_DESC)
|
||||
->page($this->_currentPage, $this->parameter->pageSize);
|
||||
$select->order('table.comments.coid', Db::SORT_DESC)
|
||||
->page($this->currentPage, $this->parameter->pageSize);
|
||||
|
||||
$this->db->fetchAll($select, [$this, 'push']);
|
||||
}
|
||||
@@ -118,29 +123,33 @@ class Widget_Comments_Admin extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 输出分页
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception|Db\Exception
|
||||
*/
|
||||
public function pageNav()
|
||||
{
|
||||
$query = $this->request->makeUriByRequest('page={page}');
|
||||
|
||||
/** 使用盒状分页 */
|
||||
$nav = new Typecho_Widget_Helper_PageNavigator_Box(false === $this->_total ? $this->_total = $this->size($this->_countSql) : $this->_total,
|
||||
$this->_currentPage, $this->parameter->pageSize, $query);
|
||||
$nav = new Box(
|
||||
false === $this->total ? $this->total = $this->size($this->countSql) : $this->total,
|
||||
$this->currentPage,
|
||||
$this->parameter->pageSize,
|
||||
$query
|
||||
);
|
||||
$nav->render(_t('«'), _t('»'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前内容结构
|
||||
*
|
||||
* @return stdClass
|
||||
* @return array|null
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
protected function ___parentContent()
|
||||
protected function ___parentContent(): ?array
|
||||
{
|
||||
$cid = isset($this->request->cid) ? $this->request->filter('int')->cid : $this->cid;
|
||||
return $this->db->fetchRow($this->widget('Widget_Abstract_Contents')->select()
|
||||
return $this->db->fetchRow(self::widget(Contents::class)->select()
|
||||
->where('table.contents.cid = ?', $cid)
|
||||
->limit(1), [$this->widget('Widget_Abstract_Contents'), 'filter']);
|
||||
->limit(1), [self::widget(Contents::class), 'filter']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 评论归档
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Comments;
|
||||
|
||||
use Typecho\Config;
|
||||
use Typecho\Cookie;
|
||||
use Typecho\Db\Exception;
|
||||
use Typecho\Router;
|
||||
use Typecho\Widget\Helper\PageNavigator\Box;
|
||||
use Typecho\Widget\Response;
|
||||
use Typecho\Widget\Request;
|
||||
use Widget\Base\Comments;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论归档组件
|
||||
@@ -18,7 +23,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
class Archive extends Comments
|
||||
{
|
||||
/**
|
||||
* 当前页
|
||||
@@ -26,7 +31,7 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_currentPage;
|
||||
private $currentPage;
|
||||
|
||||
/**
|
||||
* 所有文章个数
|
||||
@@ -34,7 +39,7 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_total = false;
|
||||
private $total = false;
|
||||
|
||||
/**
|
||||
* 子父级评论关系
|
||||
@@ -42,7 +47,7 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_threadedComments = [];
|
||||
private $threadedComments = [];
|
||||
|
||||
/**
|
||||
* _singleCommentOptions
|
||||
@@ -50,18 +55,17 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
private $_singleCommentOptions = null;
|
||||
private $singleCommentOptions = null;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param Request $request request对象
|
||||
* @param Response $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
public function __construct(Request $request, Response $response, $params = null)
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
$this->parameter->setDefault('parentId=0&commentPage=0&commentsNum=0&allowComment=1');
|
||||
@@ -78,7 +82,7 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
$args[] = '%d';
|
||||
}
|
||||
|
||||
$num = intval($this->_total);
|
||||
$num = intval($this->total);
|
||||
|
||||
echo sprintf($args[$num] ?? array_pop($args), $num);
|
||||
}
|
||||
@@ -95,8 +99,8 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
return;
|
||||
}
|
||||
|
||||
$commentsAuthor = Typecho_Cookie::get('__typecho_remember_author');
|
||||
$commentsMail = Typecho_Cookie::get('__typecho_remember_mail');
|
||||
$commentsAuthor = Cookie::get('__typecho_remember_author');
|
||||
$commentsMail = Cookie::get('__typecho_remember_mail');
|
||||
$select = $this->select()->where('table.comments.cid = ?', $this->parameter->parentId)
|
||||
->where('table.comments.status = ? OR (table.comments.author = ? AND table.comments.mail = ? AND table.comments.status = ?)', 'approved', $commentsAuthor, $commentsMail, 'waiting');
|
||||
$threadedSelect = null;
|
||||
@@ -113,7 +117,6 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
|
||||
/** 如果开启评论回复 */
|
||||
if ($this->options->commentsThreaded) {
|
||||
|
||||
foreach ($this->stack as $coid => &$comment) {
|
||||
|
||||
/** 取出父节点 */
|
||||
@@ -130,11 +133,11 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
}
|
||||
|
||||
/** 计算子节点顺序 */
|
||||
$comment['order'] = isset($this->_threadedComments[$parent])
|
||||
? count($this->_threadedComments[$parent]) + 1 : 1;
|
||||
$comment['order'] = isset($this->threadedComments[$parent])
|
||||
? count($this->threadedComments[$parent]) + 1 : 1;
|
||||
|
||||
/** 如果是子节点 */
|
||||
$this->_threadedComments[$parent][$coid] = $comment;
|
||||
$this->threadedComments[$parent][$coid] = $comment;
|
||||
} else {
|
||||
$outputComments[$coid] = $comment;
|
||||
}
|
||||
@@ -147,23 +150,26 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/** 评论排序 */
|
||||
if ('DESC' == $this->options->commentsOrder) {
|
||||
$this->stack = array_reverse($this->stack, true);
|
||||
$this->_threadedComments = array_map('array_reverse', $this->_threadedComments);
|
||||
$this->threadedComments = array_map('array_reverse', $this->threadedComments);
|
||||
}
|
||||
|
||||
/** 评论总数 */
|
||||
$this->_total = count($this->stack);
|
||||
$this->total = count($this->stack);
|
||||
|
||||
/** 对评论进行分页 */
|
||||
if ($this->options->commentsPageBreak) {
|
||||
if ('last' == $this->options->commentsPageDisplay && !$this->parameter->commentPage) {
|
||||
$this->_currentPage = ceil($this->_total / $this->options->commentsPageSize);
|
||||
$this->currentPage = ceil($this->total / $this->options->commentsPageSize);
|
||||
} else {
|
||||
$this->_currentPage = $this->parameter->commentPage ? $this->parameter->commentPage : 1;
|
||||
$this->currentPage = $this->parameter->commentPage ? $this->parameter->commentPage : 1;
|
||||
}
|
||||
|
||||
/** 截取评论 */
|
||||
$this->stack = array_slice($this->stack,
|
||||
($this->_currentPage - 1) * $this->options->commentsPageSize, $this->options->commentsPageSize);
|
||||
$this->stack = array_slice(
|
||||
$this->stack,
|
||||
($this->currentPage - 1) * $this->options->commentsPageSize,
|
||||
$this->options->commentsPageSize
|
||||
);
|
||||
|
||||
/** 评论置位 */
|
||||
$this->length = count($this->stack);
|
||||
@@ -176,11 +182,10 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 将每行的值压入堆栈
|
||||
*
|
||||
* @access public
|
||||
* @param array $value 每行的值
|
||||
* @return array
|
||||
*/
|
||||
public function push(array $value)
|
||||
public function push(array $value): array
|
||||
{
|
||||
$value = $this->filter($value);
|
||||
|
||||
@@ -208,10 +213,16 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
* @param string $splitWord 分割字符
|
||||
* @param string $template 展现配置信息
|
||||
* @return void
|
||||
* @throws \Typecho\Widget\Exception
|
||||
*/
|
||||
public function pageNav($prev = '«', $next = '»', $splitPage = 3, $splitWord = '...', $template = '')
|
||||
{
|
||||
if ($this->options->commentsPageBreak && $this->_total > $this->options->commentsPageSize) {
|
||||
public function pageNav(
|
||||
string $prev = '«',
|
||||
string $next = '»',
|
||||
int $splitPage = 3,
|
||||
string $splitWord = '...',
|
||||
string $template = ''
|
||||
) {
|
||||
if ($this->options->commentsPageBreak && $this->total > $this->options->commentsPageSize) {
|
||||
$default = [
|
||||
'wrapTag' => 'ol',
|
||||
'wrapClass' => 'page-navigator'
|
||||
@@ -228,11 +239,10 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
$pageRow = $this->parameter->parentContent;
|
||||
$pageRow['permalink'] = $pageRow['pathinfo'];
|
||||
|
||||
$query = Typecho_Router::url('comment_page', $pageRow, $this->options->index);
|
||||
$query = Router::url('comment_page', $pageRow, $this->options->index);
|
||||
|
||||
/** 使用盒状分页 */
|
||||
$nav = new Typecho_Widget_Helper_PageNavigator_Box($this->_total,
|
||||
$this->_currentPage, $this->options->commentsPageSize, $query);
|
||||
$nav = new Box($this->total, $this->currentPage, $this->options->commentsPageSize, $query);
|
||||
$nav->setPageHolder('commentPage');
|
||||
$nav->setAnchor('comments');
|
||||
|
||||
@@ -246,15 +256,13 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 列出评论
|
||||
*
|
||||
* @access private
|
||||
* @param mixed $singleCommentOptions 单个评论自定义选项
|
||||
* @return void
|
||||
*/
|
||||
public function listComments($singleCommentOptions = null)
|
||||
{
|
||||
//初始化一些变量
|
||||
$this->_singleCommentOptions = Typecho_Config::factory($singleCommentOptions);
|
||||
$this->_singleCommentOptions->setDefault([
|
||||
$this->singleCommentOptions = Config::factory($singleCommentOptions);
|
||||
$this->singleCommentOptions->setDefault([
|
||||
'before' => '<ol class="comment-list">',
|
||||
'after' => '</ol>',
|
||||
'beforeAuthor' => '',
|
||||
@@ -267,30 +275,27 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
'avatarSize' => 32,
|
||||
'defaultAvatar' => null
|
||||
]);
|
||||
$this->pluginHandle()->trigger($plugged)->listComments($this->_singleCommentOptions, $this);
|
||||
$this->pluginHandle()->trigger($plugged)->listComments($this->singleCommentOptions, $this);
|
||||
|
||||
if (!$plugged) {
|
||||
if ($this->have()) {
|
||||
echo $this->_singleCommentOptions->before;
|
||||
echo $this->singleCommentOptions->before;
|
||||
|
||||
while ($this->next()) {
|
||||
$this->threadedCommentsCallback();
|
||||
}
|
||||
|
||||
echo $this->_singleCommentOptions->after;
|
||||
echo $this->singleCommentOptions->after;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论回调函数
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function threadedCommentsCallback()
|
||||
{
|
||||
$singleCommentOptions = $this->_singleCommentOptions;
|
||||
$singleCommentOptions = $this->singleCommentOptions;
|
||||
if (function_exists('threadedComments')) {
|
||||
return threadedComments($this, $singleCommentOptions);
|
||||
}
|
||||
@@ -350,7 +355,7 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 根据深度余数输出
|
||||
*
|
||||
* @param ...$args 需要输出的值
|
||||
* @param mixed ...$args 需要输出的值
|
||||
*/
|
||||
public function levelsAlt(...$args)
|
||||
{
|
||||
@@ -377,11 +382,9 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 评论回复链接
|
||||
*
|
||||
* @access public
|
||||
* @param string $word 回复链接文字
|
||||
* @return void
|
||||
*/
|
||||
public function reply($word = '')
|
||||
public function reply(string $word = '')
|
||||
{
|
||||
if ($this->options->commentsThreaded && !$this->isTopLevel && $this->parameter->allowComment) {
|
||||
$word = empty($word) ? _t('回复') : $word;
|
||||
@@ -397,9 +400,6 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
|
||||
/**
|
||||
* 递归输出评论
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
public function threadedComments()
|
||||
{
|
||||
@@ -410,7 +410,7 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
$this->sequence ++;
|
||||
|
||||
//在子评论之前输出
|
||||
echo $this->_singleCommentOptions->before;
|
||||
echo $this->singleCommentOptions->before;
|
||||
|
||||
foreach ($children as $child) {
|
||||
$this->row = $child;
|
||||
@@ -419,7 +419,7 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
}
|
||||
|
||||
//在子评论之后输出
|
||||
echo $this->_singleCommentOptions->after;
|
||||
echo $this->singleCommentOptions->after;
|
||||
|
||||
$this->sequence --;
|
||||
}
|
||||
@@ -428,11 +428,9 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 取消评论回复链接
|
||||
*
|
||||
* @access public
|
||||
* @param string $word 取消回复链接文字
|
||||
* @return void
|
||||
*/
|
||||
public function cancelReply($word = '')
|
||||
public function cancelReply(string $word = '')
|
||||
{
|
||||
if ($this->options->commentsThreaded) {
|
||||
$word = empty($word) ? _t('取消回复') : $word;
|
||||
@@ -449,16 +447,14 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 获取当前评论链接
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___permalink()
|
||||
protected function ___permalink(): string
|
||||
{
|
||||
|
||||
if ($this->options->commentsPageBreak) {
|
||||
$pageRow = ['permalink' => $this->parentContent['pathinfo'], 'commentPage' => $this->_currentPage];
|
||||
return Typecho_Router::url('comment_page',
|
||||
$pageRow, $this->options->index) . '#' . $this->theId;
|
||||
$pageRow = ['permalink' => $this->parentContent['pathinfo'], 'commentPage' => $this->currentPage];
|
||||
return Router::url('comment_page', $pageRow, $this->options->index) . '#' . $this->theId;
|
||||
}
|
||||
|
||||
return $this->parentContent['permalink'] . '#' . $this->theId;
|
||||
@@ -467,22 +463,20 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 子评论
|
||||
*
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function ___children()
|
||||
protected function ___children(): array
|
||||
{
|
||||
return $this->options->commentsThreaded && !$this->isTopLevel && isset($this->_threadedComments[$this->coid])
|
||||
? $this->_threadedComments[$this->coid] : [];
|
||||
return $this->options->commentsThreaded && !$this->isTopLevel && isset($this->threadedComments[$this->coid])
|
||||
? $this->threadedComments[$this->coid] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否到达顶层
|
||||
*
|
||||
* @access protected
|
||||
* @return boolean
|
||||
*/
|
||||
protected function ___isTopLevel()
|
||||
protected function ___isTopLevel(): bool
|
||||
{
|
||||
return $this->levels > $this->options->commentsMaxNestingLevels - 2;
|
||||
}
|
||||
@@ -490,10 +484,9 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 重载内容获取
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return array|null
|
||||
*/
|
||||
protected function ___parentContent()
|
||||
protected function ___parentContent(): ?array
|
||||
{
|
||||
return $this->parameter->parentContent;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* Typecho Blog Platform
|
||||
*
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Comments;
|
||||
|
||||
use Typecho\Db\Exception;
|
||||
use Widget\Base\Comments;
|
||||
use Widget\DoInterface;
|
||||
use Widget\Notice;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论编辑组件
|
||||
@@ -17,13 +20,10 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_Interface_Do
|
||||
class Edit extends Comments implements DoInterface
|
||||
{
|
||||
/**
|
||||
* 标记为待审核
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function waitingComment()
|
||||
{
|
||||
@@ -32,13 +32,16 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
|
||||
foreach ($comments as $comment) {
|
||||
if ($this->mark($comment, 'waiting')) {
|
||||
$updateRows ++;
|
||||
$updateRows++;
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被标记为待审核') : _t('没有评论被标记为待审核'),
|
||||
$updateRows > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$updateRows > 0 ? _t('评论已经被标记为待审核') : _t('没有评论被标记为待审核'),
|
||||
$updateRows > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -47,10 +50,10 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
/**
|
||||
* 标记评论状态
|
||||
*
|
||||
* @access private
|
||||
* @param integer $coid 评论主键
|
||||
* @param string $status 状态
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
private function mark($coid, $status)
|
||||
{
|
||||
@@ -73,7 +76,8 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
/** 更新相关内容的评论数 */
|
||||
if ('approved' == $comment['status'] && 'approved' != $status) {
|
||||
$this->db->query($this->db->update('table.contents')
|
||||
->expression('commentsNum', 'commentsNum - 1')->where('cid = ? AND commentsNum > 0', $comment['cid']));
|
||||
->expression('commentsNum', 'commentsNum - 1')
|
||||
->where('cid = ? AND commentsNum > 0', $comment['cid']));
|
||||
} elseif ('approved' != $comment['status'] && 'approved' == $status) {
|
||||
$this->db->query($this->db->update('table.contents')
|
||||
->expression('commentsNum', 'commentsNum + 1')->where('cid = ?', $comment['cid']));
|
||||
@@ -88,8 +92,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
/**
|
||||
* 标记为垃圾
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function spamComment()
|
||||
{
|
||||
@@ -98,13 +101,16 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
|
||||
foreach ($comments as $comment) {
|
||||
if ($this->mark($comment, 'spam')) {
|
||||
$updateRows ++;
|
||||
$updateRows++;
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被标记为垃圾') : _t('没有评论被标记为垃圾'),
|
||||
$updateRows > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$updateRows > 0 ? _t('评论已经被标记为垃圾') : _t('没有评论被标记为垃圾'),
|
||||
$updateRows > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -113,8 +119,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
/**
|
||||
* 标记为展现
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function approvedComment()
|
||||
{
|
||||
@@ -123,13 +128,16 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
|
||||
foreach ($comments as $comment) {
|
||||
if ($this->mark($comment, 'approved')) {
|
||||
$updateRows ++;
|
||||
$updateRows++;
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($updateRows > 0 ? _t('评论已经被通过') : _t('没有评论被通过'),
|
||||
$updateRows > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$updateRows > 0 ? _t('评论已经被通过') : _t('没有评论被通过'),
|
||||
$updateRows > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -138,8 +146,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
/**
|
||||
* 删除评论
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteComment()
|
||||
{
|
||||
@@ -164,12 +171,11 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
|
||||
$this->pluginHandle()->finishDelete($comment, $this);
|
||||
|
||||
$deleteRows ++;
|
||||
$deleteRows++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->isAjax()) {
|
||||
|
||||
if ($deleteRows > 0) {
|
||||
$this->response->throwJson([
|
||||
'success' => 1,
|
||||
@@ -184,8 +190,11 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
|
||||
} else {
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteRows > 0 ? _t('评论已经被删除') : _t('没有评论被删除'),
|
||||
$deleteRows > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$deleteRows > 0 ? _t('评论已经被删除') : _t('没有评论被删除'),
|
||||
$deleteRows > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -195,8 +204,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
/**
|
||||
* 删除所有垃圾评论
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteSpamComment()
|
||||
{
|
||||
@@ -212,9 +220,10 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
$deleteRows = $this->db->query($deleteQuery);
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteRows > 0 ?
|
||||
_t('所有垃圾评论已经被删除') : _t('没有垃圾评论被删除'),
|
||||
$deleteRows > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)->set(
|
||||
$deleteRows > 0 ? _t('所有垃圾评论已经被删除') : _t('没有垃圾评论被删除'),
|
||||
$deleteRows > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -223,8 +232,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
/**
|
||||
* 获取可编辑的评论
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
@@ -233,27 +241,22 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
->where('coid = ?', $coid)->limit(1), [$this, 'push']);
|
||||
|
||||
if ($comment && $this->commentIsWriteable()) {
|
||||
|
||||
$this->response->throwJson([
|
||||
'success' => 1,
|
||||
'comment' => $comment
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
$this->response->throwJson([
|
||||
'success' => 0,
|
||||
'message' => _t('获取评论失败')
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑评论
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function editComment()
|
||||
{
|
||||
@@ -262,7 +265,6 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
->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;
|
||||
@@ -296,8 +298,7 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
/**
|
||||
* 回复评论
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function replyComment()
|
||||
{
|
||||
@@ -306,7 +307,6 @@ class Widget_Comments_Edit extends Widget_Abstract_Comments implements Widget_In
|
||||
->where('coid = ?', $coid)->limit(1), [$this, 'push']);
|
||||
|
||||
if ($commentSelect && $this->commentIsWriteable()) {
|
||||
|
||||
$comment = [
|
||||
'cid' => $commentSelect['cid'],
|
||||
'created' => $this->options->time,
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 回响归档
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Comments;
|
||||
|
||||
use Typecho\Config;
|
||||
use Typecho\Db\Exception;
|
||||
use Typecho\Widget\Request;
|
||||
use Typecho\Widget\Response;
|
||||
use Widget\Base\Comments;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回响归档组件
|
||||
@@ -18,7 +20,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Comments_Ping extends Widget_Abstract_Comments
|
||||
class Ping extends Comments
|
||||
{
|
||||
/**
|
||||
* _customSinglePingCallback
|
||||
@@ -26,32 +28,31 @@ class Widget_Comments_Ping extends Widget_Abstract_Comments
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
private $_customSinglePingCallback = false;
|
||||
private $customSinglePingCallback = false;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param Request $request request对象
|
||||
* @param Response $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
public function __construct(Request $request, Response $response, $params = null)
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
$this->parameter->setDefault('parentId=0');
|
||||
|
||||
/** 初始化回调函数 */
|
||||
if (function_exists('singlePing')) {
|
||||
$this->_customSinglePingCallback = true;
|
||||
$this->customSinglePingCallback = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出文章回响数
|
||||
*
|
||||
* @param ...$args 评论数格式化数据
|
||||
* @param mixed ...$args 评论数格式化数据
|
||||
*/
|
||||
public function num(...$args)
|
||||
{
|
||||
@@ -67,6 +68,7 @@ class Widget_Comments_Ping extends Widget_Abstract_Comments
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -85,15 +87,13 @@ class Widget_Comments_Ping extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 列出回响
|
||||
*
|
||||
* @access private
|
||||
* @param mixed $singlePingOptions 单个回响自定义选项
|
||||
* @return void
|
||||
*/
|
||||
public function listPings($singlePingOptions = null)
|
||||
{
|
||||
if ($this->have()) {
|
||||
//初始化一些变量
|
||||
$parsedSinglePingOptions = Typecho_Config::factory($singlePingOptions);
|
||||
$parsedSinglePingOptions = Config::factory($singlePingOptions);
|
||||
$parsedSinglePingOptions->setDefault([
|
||||
'before' => '<ol class="ping-list">',
|
||||
'after' => '</ol>',
|
||||
@@ -117,13 +117,11 @@ class Widget_Comments_Ping extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 回响回调函数
|
||||
*
|
||||
* @access private
|
||||
* @param string $singlePingOptions 单个回响自定义选项
|
||||
* @return void
|
||||
*/
|
||||
private function singlePingCallback($singlePingOptions)
|
||||
private function singlePingCallback(string $singlePingOptions)
|
||||
{
|
||||
if ($this->_customSinglePingCallback) {
|
||||
if ($this->customSinglePingCallback) {
|
||||
return singlePing($this, $singlePingOptions);
|
||||
}
|
||||
|
||||
@@ -149,10 +147,9 @@ class Widget_Comments_Ping extends Widget_Abstract_Comments
|
||||
/**
|
||||
* 重载内容获取
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return array|null
|
||||
*/
|
||||
protected function ___parentContent()
|
||||
protected function ___parentContent(): ?array
|
||||
{
|
||||
return $this->parameter->parentContent;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* Typecho Blog Platform
|
||||
*
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Comments;
|
||||
|
||||
use Typecho\Db;
|
||||
use Typecho\Db\Exception;
|
||||
use Typecho\Widget\Request;
|
||||
use Typecho\Widget\Response;
|
||||
use Widget\Base\Comments;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近评论组件
|
||||
@@ -16,34 +20,34 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Comments_Recent extends Widget_Abstract_Comments
|
||||
class Recent extends Comments
|
||||
{
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param Request $request request对象
|
||||
* @param Response $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
public function __construct(Request $request, Response $response, $params = null)
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
$this->parameter->setDefault(['pageSize' => $this->options->commentsListSize, 'parentId' => 0, 'ignoreAuthor' => false]);
|
||||
$this->parameter->setDefault(
|
||||
['pageSize' => $this->options->commentsListSize, 'parentId' => 0, 'ignoreAuthor' => false]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$select = $this->select()->limit($this->parameter->pageSize)
|
||||
->where('table.comments.status = ?', 'approved')
|
||||
->order('table.comments.coid', Typecho_Db::SORT_DESC);
|
||||
->order('table.comments.coid', Db::SORT_DESC);
|
||||
|
||||
if ($this->parameter->parentId) {
|
||||
$select->where('cid = ?', $this->parameter->parentId);
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 文件管理列表
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Attachment;
|
||||
|
||||
use Typecho\Config;
|
||||
use Typecho\Db;
|
||||
use Typecho\Db\Exception;
|
||||
use Typecho\Db\Query;
|
||||
use Typecho\Widget\Helper\PageNavigator\Box;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件管理列表组件
|
||||
@@ -18,50 +21,39 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Attachment_Admin extends Widget_Abstract_Contents
|
||||
class Admin extends Contents
|
||||
{
|
||||
/**
|
||||
* 用于计算数值的语句对象
|
||||
*
|
||||
* @access private
|
||||
* @var Typecho_Db_Query
|
||||
* @var Query
|
||||
*/
|
||||
private $_countSql;
|
||||
private $countSql;
|
||||
|
||||
/**
|
||||
* 所有文章个数
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_total = false;
|
||||
|
||||
/**
|
||||
* 分页大小
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $pageSize;
|
||||
private $total = false;
|
||||
|
||||
/**
|
||||
* 当前页
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_currentPage;
|
||||
private $currentPage;
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception|\Typecho\Widget\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->parameter->setDefault('pageSize=20');
|
||||
$this->_currentPage = $this->request->get('page', 1);
|
||||
$this->currentPage = $this->request->get('page', 1);
|
||||
|
||||
/** 构建基础查询 */
|
||||
$select = $this->select()->where('table.contents.type = ?', 'attachment');
|
||||
@@ -85,11 +77,11 @@ class Widget_Contents_Attachment_Admin extends Widget_Abstract_Contents
|
||||
}
|
||||
|
||||
/** 给计算数目对象赋值,克隆对象 */
|
||||
$this->_countSql = clone $select;
|
||||
$this->countSql = clone $select;
|
||||
|
||||
/** 提交查询 */
|
||||
$select->order('table.contents.created', Typecho_Db::SORT_DESC)
|
||||
->page($this->_currentPage, $this->parameter->pageSize);
|
||||
$select->order('table.contents.created', Db::SORT_DESC)
|
||||
->page($this->currentPage, $this->parameter->pageSize);
|
||||
|
||||
$this->db->fetchAll($select, [$this, 'push']);
|
||||
}
|
||||
@@ -97,29 +89,34 @@ class Widget_Contents_Attachment_Admin extends Widget_Abstract_Contents
|
||||
/**
|
||||
* 输出分页
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception|\Typecho\Widget\Exception
|
||||
*/
|
||||
public function pageNav()
|
||||
{
|
||||
$query = $this->request->makeUriByRequest('page={page}');
|
||||
|
||||
/** 使用盒状分页 */
|
||||
$nav = new Typecho_Widget_Helper_PageNavigator_Box(false === $this->_total ? $this->_total = $this->size($this->_countSql) : $this->_total,
|
||||
$this->_currentPage, $this->parameter->pageSize, $query);
|
||||
$nav = new Box(
|
||||
false === $this->total ? $this->total = $this->size($this->countSql) : $this->total,
|
||||
$this->currentPage,
|
||||
$this->parameter->pageSize,
|
||||
$query
|
||||
);
|
||||
|
||||
$nav->render('«', '»');
|
||||
}
|
||||
|
||||
/**
|
||||
* 所属文章
|
||||
*
|
||||
* @access protected
|
||||
* @return Typecho_Config
|
||||
* @return Config
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function ___parentPost()
|
||||
protected function ___parentPost(): Config
|
||||
{
|
||||
return new Typecho_Config($this->db->fetchRow(
|
||||
$this->select()->where('table.contents.cid = ?', $this->parentId)
|
||||
->limit(1)));
|
||||
return new Config($this->db->fetchRow(
|
||||
$this->select()->where('table.contents.cid = ?', $this->parentId)->limit(1)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 编辑文章
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Attachment;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Widget\Exception;
|
||||
use Typecho\Widget\Helper\Form;
|
||||
use Typecho\Widget\Helper\Layout;
|
||||
use Widget\DoInterface;
|
||||
use Widget\Contents\Post\Edit as PostEdit;
|
||||
use Widget\Notice;
|
||||
use Widget\Upload;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章组件
|
||||
@@ -19,13 +24,12 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implements Widget_Interface_Do
|
||||
class Edit extends PostEdit implements DoInterface
|
||||
{
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception|\Typecho\Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -33,17 +37,19 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
$this->user->pass('contributor');
|
||||
|
||||
/** 获取文章内容 */
|
||||
if ((isset($this->request->cid) && 'delete' != $this->request->do
|
||||
&& 'insert' != $this->request->do) || 'update' == $this->request->do) {
|
||||
if (
|
||||
(isset($this->request->cid) && 'delete' != $this->request->do
|
||||
&& 'insert' != $this->request->do) || 'update' == $this->request->do
|
||||
) {
|
||||
$this->db->fetchRow($this->select()
|
||||
->where('table.contents.type = ?', 'attachment')
|
||||
->where('table.contents.cid = ?', $this->request->filter('int')->cid)
|
||||
->limit(1), [$this, 'push']);
|
||||
|
||||
if (!$this->have()) {
|
||||
throw new Typecho_Widget_Exception(_t('文件不存在'), 404);
|
||||
} elseif ($this->have() && !$this->allow('edit')) {
|
||||
throw new Typecho_Widget_Exception(_t('没有编辑权限'), 403);
|
||||
throw new Exception(_t('文件不存在'), 404);
|
||||
} elseif (!$this->allow('edit')) {
|
||||
throw new Exception(_t('没有编辑权限'), 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,14 +57,13 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
/**
|
||||
* 判断文件名转换到缩略名后是否合法
|
||||
*
|
||||
* @access public
|
||||
* @param string $name 文件名
|
||||
* @return boolean
|
||||
*/
|
||||
public function nameToSlug($name)
|
||||
public function nameToSlug(string $name): bool
|
||||
{
|
||||
if (empty($this->request->slug)) {
|
||||
$slug = Typecho_Common::slugName($name);
|
||||
$slug = Common::slugName($name);
|
||||
if (empty($slug) || !$this->slugExists($name)) {
|
||||
return false;
|
||||
}
|
||||
@@ -70,16 +75,16 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
/**
|
||||
* 判断文件缩略名是否存在
|
||||
*
|
||||
* @access public
|
||||
* @param string $slug 缩略名
|
||||
* @return boolean
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function slugExists($slug)
|
||||
public function slugExists(string $slug): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.contents')
|
||||
->where('type = ?', 'attachment')
|
||||
->where('slug = ?', Typecho_Common::slugName($slug))
|
||||
->where('slug = ?', Common::slugName($slug))
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->cid) {
|
||||
@@ -87,14 +92,14 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
}
|
||||
|
||||
$attachment = $this->db->fetchRow($select);
|
||||
return $attachment ? false : true;
|
||||
return !$attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws \Typecho\Db\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateAttachment()
|
||||
{
|
||||
@@ -104,7 +109,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
|
||||
/** 取出数据 */
|
||||
$input = $this->request->from('name', 'slug', 'description');
|
||||
$input['slug'] = Typecho_Common::slugName(empty($input['slug']) ? $input['name'] : $input['slug']);
|
||||
$input['slug'] = Common::slugName(empty($input['slug']) ? $input['name'] : $input['slug']);
|
||||
|
||||
$attachment['title'] = $input['name'];
|
||||
$attachment['slug'] = $input['slug'];
|
||||
@@ -119,65 +124,72 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
$updateRows = $this->update($attachment, $this->db->sql()->where('cid = ?', $cid));
|
||||
|
||||
if ($updateRows > 0) {
|
||||
|
||||
$this->db->fetchRow($this->select()
|
||||
->where('table.contents.type = ?', 'attachment')
|
||||
->where('table.contents.cid = ?', $cid)
|
||||
->limit(1), [$this, 'push']);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->theId);
|
||||
self::widget('Widget_Notice')->highlight($this->theId);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set('publish' == $this->status ?
|
||||
self::widget('Widget_Notice')->set('publish' == $this->status ?
|
||||
_t('文件 <a href="%s">%s</a> 已经被更新', $this->permalink, $this->title) :
|
||||
_t('未归档文件 %s 已经被更新', $this->title), 'success');
|
||||
|
||||
}
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-medias.php?' .
|
||||
$this->response->redirect(Common::url('manage-medias.php?' .
|
||||
$this->getPageOffsetQuery($cid, $this->status), $this->options->adminUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成表单
|
||||
*
|
||||
* @access public
|
||||
* @return Typecho_Widget_Helper_Form_Element
|
||||
* @return Form
|
||||
*/
|
||||
public function form()
|
||||
public function form(): Form
|
||||
{
|
||||
/** 构建表格 */
|
||||
$form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/contents-attachment-edit'),
|
||||
Typecho_Widget_Helper_Form::POST_METHOD);
|
||||
$form = new Form($this->security->getIndex('/action/contents-attachment-edit'), Form::POST_METHOD);
|
||||
|
||||
/** 文件名称 */
|
||||
$name = new Typecho_Widget_Helper_Form_Element_Text('name', null, $this->title, _t('标题') . ' *');
|
||||
$name = new Form\Element\Text('name', null, $this->title, _t('标题') . ' *');
|
||||
$form->addInput($name);
|
||||
|
||||
/** 文件缩略名 */
|
||||
$slug = new Typecho_Widget_Helper_Form_Element_Text('slug', null, $this->slug, _t('缩略名'),
|
||||
_t('文件缩略名用于创建友好的链接形式,建议使用字母,数字,下划线和横杠.'));
|
||||
$slug = new Form\Element\Text(
|
||||
'slug',
|
||||
null,
|
||||
$this->slug,
|
||||
_t('缩略名'),
|
||||
_t('文件缩略名用于创建友好的链接形式,建议使用字母,数字,下划线和横杠.')
|
||||
);
|
||||
$form->addInput($slug);
|
||||
|
||||
/** 文件描述 */
|
||||
$description = new Typecho_Widget_Helper_Form_Element_Textarea('description', null, $this->attachment->description,
|
||||
_t('描述'), _t('此文字用于描述文件,在有的主题中它会被显示.'));
|
||||
$description = new Form\Element\Textarea(
|
||||
'description',
|
||||
null,
|
||||
$this->attachment->description,
|
||||
_t('描述'),
|
||||
_t('此文字用于描述文件,在有的主题中它会被显示.')
|
||||
);
|
||||
$form->addInput($description);
|
||||
|
||||
/** 分类动作 */
|
||||
$do = new Typecho_Widget_Helper_Form_Element_Hidden('do', null, 'update');
|
||||
$do = new Form\Element\Hidden('do', null, 'update');
|
||||
$form->addInput($do);
|
||||
|
||||
/** 分类主键 */
|
||||
$cid = new Typecho_Widget_Helper_Form_Element_Hidden('cid', null, $this->cid);
|
||||
$cid = new Form\Element\Hidden('cid', null, $this->cid);
|
||||
$form->addInput($cid);
|
||||
|
||||
/** 提交按钮 */
|
||||
$submit = new Typecho_Widget_Helper_Form_Element_Submit(null, null, _t('提交修改'));
|
||||
$submit = new Form\Element\Submit(null, null, _t('提交修改'));
|
||||
$submit->input->setAttribute('class', 'btn primary');
|
||||
$delete = new Typecho_Widget_Helper_Layout('a', [
|
||||
$delete = new Layout('a', [
|
||||
'href' => $this->security->getIndex('/action/contents-attachment-edit?do=delete&cid=' . $this->cid),
|
||||
'class' => 'operate-delete',
|
||||
'lang' => _t('你确认删除文件 %s 吗?', $this->attachment->name)
|
||||
@@ -195,22 +207,26 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
/**
|
||||
* 获取页面偏移的URL Query
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $cid 文件id
|
||||
* @param string $status 状态
|
||||
* @param string|null $status 状态
|
||||
* @return string
|
||||
* @throws \Typecho\Db\Exception|Exception
|
||||
*/
|
||||
protected function getPageOffsetQuery($cid, $status = null)
|
||||
protected function getPageOffsetQuery(int $cid, string $status = null): string
|
||||
{
|
||||
return 'page=' . $this->getPageOffset('cid', $cid, 'attachment', $status,
|
||||
$this->user->pass('editor', true) ? 0 : $this->user->uid);
|
||||
return 'page=' . $this->getPageOffset(
|
||||
'cid',
|
||||
$cid,
|
||||
'attachment',
|
||||
$status,
|
||||
$this->user->pass('editor', true) ? 0 : $this->user->uid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function deleteAttachment()
|
||||
{
|
||||
@@ -229,7 +245,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
|
||||
if ($this->isWriteable(clone $condition) && $this->delete($condition)) {
|
||||
/** 删除文件 */
|
||||
Widget_Upload::deleteHandle($row);
|
||||
Upload::deleteHandle($row);
|
||||
|
||||
/** 删除评论 */
|
||||
$this->db->query($this->db->delete('table.comments')
|
||||
@@ -238,7 +254,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
// 完成删除插件接口
|
||||
$this->pluginHandle()->finishDelete($post, $this);
|
||||
|
||||
$deleteCount ++;
|
||||
$deleteCount++;
|
||||
}
|
||||
|
||||
unset($condition);
|
||||
@@ -249,11 +265,14 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
: ['code' => 500, 'message' => _t('没有文件被删除')]);
|
||||
} else {
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('文件已经被删除') : _t('没有文件被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$deleteCount > 0 ? _t('文件已经被删除') : _t('没有文件被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-medias.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-medias.php', $this->options->adminUrl));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +281,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function clearAttachment()
|
||||
{
|
||||
@@ -273,7 +293,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
->from('table.contents')
|
||||
->where('type = ? AND parent = ?', 'attachment', 0)
|
||||
->page($page, 100)), 'cid');
|
||||
$page ++;
|
||||
$page++;
|
||||
|
||||
foreach ($posts as $post) {
|
||||
// 删除插件接口
|
||||
@@ -287,7 +307,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
|
||||
if ($this->isWriteable(clone $condition) && $this->delete($condition)) {
|
||||
/** 删除文件 */
|
||||
Widget_Upload::deleteHandle($row);
|
||||
Upload::deleteHandle($row);
|
||||
|
||||
/** 删除评论 */
|
||||
$this->db->query($this->db->delete('table.comments')
|
||||
@@ -298,7 +318,7 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
// 完成删除插件接口
|
||||
$this->pluginHandle()->finishDelete($post, $this);
|
||||
|
||||
$deleteCount ++;
|
||||
$deleteCount++;
|
||||
}
|
||||
|
||||
unset($condition);
|
||||
@@ -306,11 +326,13 @@ class Widget_Contents_Attachment_Edit extends Widget_Contents_Post_Edit implemen
|
||||
} while (count($posts) == 100);
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('未归档文件已经被清理') : _t('没有未归档文件被清理'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
self::widget('Widget_Notice')->set(
|
||||
$deleteCount > 0 ? _t('未归档文件已经被清理') : _t('没有未归档文件被清理'),
|
||||
$deleteCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-medias.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-medias.php', $this->options->adminUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 文章相关文件
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Attachment;
|
||||
|
||||
use Typecho\Db;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章相关文件组件
|
||||
@@ -18,13 +17,14 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Attachment_Related extends Widget_Abstract_Contents
|
||||
class Related extends Contents
|
||||
{
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -42,7 +42,7 @@ class Widget_Contents_Attachment_Related extends Widget_Abstract_Contents
|
||||
$select->where('table.contents.parent = ?', $this->parameter->parentId);
|
||||
|
||||
/** 提交查询 */
|
||||
$select->order('table.contents.created', Typecho_Db::SORT_ASC);
|
||||
$select->order('table.contents.created', Db::SORT_ASC);
|
||||
|
||||
if ($this->parameter->limit > 0) {
|
||||
$select->limit($this->parameter->limit);
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
|
||||
namespace Widget\Contents\Attachment;
|
||||
|
||||
use Typecho\Db;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
/**
|
||||
* 没有关联的文件
|
||||
*
|
||||
@@ -18,13 +26,14 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Attachment_Unattached extends Widget_Abstract_Contents
|
||||
class Unattached extends Contents
|
||||
{
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -36,7 +45,7 @@ class Widget_Contents_Attachment_Unattached extends Widget_Abstract_Contents
|
||||
$this->where('table.contents.authorId = ?', $this->user->uid);
|
||||
|
||||
/** 提交查询 */
|
||||
$select->order('table.contents.created', Typecho_Db::SORT_DESC);
|
||||
$select->order('table.contents.created', Db::SORT_DESC);
|
||||
|
||||
$this->db->fetchAll($select, [$this, 'push']);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 独立页面管理列表
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Page;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Db;
|
||||
use Widget\Contents\Post\Admin as PostAdmin;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 独立页面管理列表组件
|
||||
@@ -18,18 +18,24 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Page_Admin extends Widget_Contents_Post_Admin
|
||||
class Admin extends PostAdmin
|
||||
{
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** 过滤状态 */
|
||||
$select = $this->select()->where('table.contents.type = ? OR (table.contents.type = ? AND table.contents.parent = ?)', 'page', 'page_draft', 0);
|
||||
$select = $this->select()->where(
|
||||
'table.contents.type = ? OR (table.contents.type = ? AND table.contents.parent = ?)',
|
||||
'page',
|
||||
'page_draft',
|
||||
0
|
||||
);
|
||||
|
||||
/** 过滤标题 */
|
||||
if (null != ($keywords = $this->request->keywords)) {
|
||||
@@ -38,14 +44,14 @@ class Widget_Contents_Page_Admin extends Widget_Contents_Post_Admin
|
||||
$args[] = implode(' OR ', array_fill(0, count($keywordsList), 'table.contents.title LIKE ?'));
|
||||
|
||||
foreach ($keywordsList as $keyword) {
|
||||
$args[] = '%' . Typecho_Common::filterSearchQuery($keyword) . '%';
|
||||
$args[] = '%' . Common::filterSearchQuery($keyword) . '%';
|
||||
}
|
||||
|
||||
call_user_func_array([$select, 'where'], $args);
|
||||
}
|
||||
|
||||
/** 提交查询 */
|
||||
$select->order('table.contents.order', Typecho_Db::SORT_ASC);
|
||||
$select->order('table.contents.order', Db::SORT_ASC);
|
||||
|
||||
$this->db->fetchAll($select, [$this, 'push']);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 编辑页面
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Page;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Date;
|
||||
use Typecho\Widget\Exception;
|
||||
use Widget\Contents\Post\Edit as PostEdit;
|
||||
use Widget\DoInterface;
|
||||
use Widget\Notice;
|
||||
use Widget\Service;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页面组件
|
||||
@@ -19,7 +23,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Widget_Interface_Do
|
||||
class Edit extends PostEdit implements DoInterface
|
||||
{
|
||||
/**
|
||||
* 自定义字段的hook名称
|
||||
@@ -34,6 +38,8 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -41,35 +47,39 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
$this->user->pass('editor');
|
||||
|
||||
/** 获取文章内容 */
|
||||
if (!empty($this->request->cid) && 'delete' != $this->request->do
|
||||
&& 'sort' != $this->request->do) {
|
||||
if (!empty($this->request->cid) && 'delete' != $this->request->do && 'sort' != $this->request->do) {
|
||||
$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)
|
||||
->limit(1), [$this, 'push']);
|
||||
|
||||
if ('page_draft' == $this->status && $this->parent) {
|
||||
$this->response->redirect(Typecho_Common::url('write-page.php?cid=' . $this->parent, $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('write-page.php?cid=' . $this->parent, $this->options->adminUrl));
|
||||
}
|
||||
|
||||
if (!$this->have()) {
|
||||
throw new Typecho_Widget_Exception(_t('页面不存在'), 404);
|
||||
} elseif ($this->have() && !$this->allow('edit')) {
|
||||
throw new Typecho_Widget_Exception(_t('没有编辑权限'), 403);
|
||||
throw new Exception(_t('页面不存在'), 404);
|
||||
} elseif (!$this->allow('edit')) {
|
||||
throw new Exception(_t('没有编辑权限'), 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布文章
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function writePage()
|
||||
{
|
||||
$contents = $this->request->from('text', 'template', 'allowComment',
|
||||
'allowPing', 'allowFeed', 'slug', 'order', 'visibility');
|
||||
$contents = $this->request->from(
|
||||
'text',
|
||||
'template',
|
||||
'allowComment',
|
||||
'allowPing',
|
||||
'allowFeed',
|
||||
'slug',
|
||||
'order',
|
||||
'visibility'
|
||||
);
|
||||
|
||||
$contents['title'] = $this->request->get('title', _t('未命名页面'));
|
||||
$contents['created'] = $this->getCreated();
|
||||
@@ -90,16 +100,19 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
$this->pluginHandle()->finishPublish($contents, $this);
|
||||
|
||||
/** 发送ping */
|
||||
$this->widget('Widget_Service')->sendPing($this->cid);
|
||||
self::widget(Service::class)->sendPing($this->cid);
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('页面 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title), 'success');
|
||||
self::widget(Notice::class)->set(
|
||||
_t('页面 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title),
|
||||
'success'
|
||||
);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->theId);
|
||||
self::widget(Notice::class)->highlight($this->theId);
|
||||
|
||||
/** 页面跳转 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-pages.php?', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-pages.php?', $this->options->adminUrl));
|
||||
} else {
|
||||
/** 保存文章 */
|
||||
$contents['type'] = 'page_draft';
|
||||
@@ -109,10 +122,10 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
$this->pluginHandle()->finishSave($contents, $this);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->cid);
|
||||
self::widget(Notice::class)->highlight($this->cid);
|
||||
|
||||
if ($this->request->isAjax()) {
|
||||
$created = new Typecho_Date($this->options->time);
|
||||
$created = new Date($this->options->time);
|
||||
$this->response->throwJson([
|
||||
'success' => 1,
|
||||
'time' => $created->format('H:i:s A'),
|
||||
@@ -121,10 +134,10 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
]);
|
||||
} else {
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('草稿 "%s" 已经被保存', $this->title), 'success');
|
||||
self::widget(Notice::class)->set(_t('草稿 "%s" 已经被保存', $this->title), 'success');
|
||||
|
||||
/** 返回原页面 */
|
||||
$this->response->redirect(Typecho_Common::url('write-page.php?cid=' . $this->cid, $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('write-page.php?cid=' . $this->cid, $this->options->adminUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,8 +145,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
/**
|
||||
* 标记页面
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function markPage()
|
||||
{
|
||||
@@ -159,8 +171,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
// 处理草稿
|
||||
$draft = $this->db->fetchRow($this->db->select('cid')
|
||||
->from('table.contents')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?',
|
||||
$page, 'page_draft')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'page_draft')
|
||||
->limit(1));
|
||||
|
||||
if (!empty($draft)) {
|
||||
@@ -171,15 +182,18 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
// 完成标记插件接口
|
||||
$this->pluginHandle()->finishMark($status, $page, $this);
|
||||
|
||||
$markCount ++;
|
||||
$markCount++;
|
||||
}
|
||||
|
||||
unset($condition);
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($markCount > 0 ? _t('页面已经被标记为<strong>%s</strong>', $statusList[$status]) : _t('没有页面被标记'),
|
||||
$markCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$markCount > 0 ? _t('页面已经被标记为<strong>%s</strong>', $statusList[$status]) : _t('没有页面被标记'),
|
||||
$markCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -188,8 +202,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
/**
|
||||
* 删除页面
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function deletePage()
|
||||
{
|
||||
@@ -218,8 +231,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
/** 删除草稿 */
|
||||
$draft = $this->db->fetchRow($this->db->select('cid')
|
||||
->from('table.contents')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?',
|
||||
$page, 'page_draft')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'page_draft')
|
||||
->limit(1));
|
||||
|
||||
/** 删除自定义字段 */
|
||||
@@ -233,13 +245,16 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
// 完成删除插件接口
|
||||
$this->pluginHandle()->finishDelete($page, $this);
|
||||
|
||||
$deleteCount ++;
|
||||
$deleteCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('页面已经被删除') : _t('没有页面被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$deleteCount > 0 ? _t('页面已经被删除') : _t('没有页面被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -248,8 +263,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
/**
|
||||
* 删除页面所属草稿
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function deletePageDraft()
|
||||
{
|
||||
@@ -260,20 +274,22 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
/** 删除草稿 */
|
||||
$draft = $this->db->fetchRow($this->db->select('cid')
|
||||
->from('table.contents')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?',
|
||||
$page, 'page_draft')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'page_draft')
|
||||
->limit(1));
|
||||
|
||||
if ($draft) {
|
||||
$this->deleteDraft($draft['cid']);
|
||||
$this->deleteFields($draft['cid']);
|
||||
$deleteCount ++;
|
||||
$deleteCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('草稿已经被删除') : _t('没有草稿被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$deleteCount > 0 ? _t('草稿已经被删除') : _t('没有草稿被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -282,8 +298,7 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
/**
|
||||
* 页面排序
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function sortPage()
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 独立页面列表
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Page;
|
||||
|
||||
use Typecho\Db;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 独立页面列表组件
|
||||
@@ -19,20 +18,21 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Page_List extends Widget_Abstract_Contents
|
||||
class Rows extends Contents
|
||||
{
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$select = $this->select()->where('table.contents.type = ?', 'page')
|
||||
->where('table.contents.status = ?', 'publish')
|
||||
->where('table.contents.created < ?', $this->options->time)
|
||||
->order('table.contents.order', Typecho_Db::SORT_ASC);
|
||||
->order('table.contents.order', Db::SORT_ASC);
|
||||
|
||||
//去掉自定义首页
|
||||
$frontPage = explode(':', $this->options->frontPage);
|
||||
@@ -1,14 +1,17 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 文章管理列表
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Post;
|
||||
|
||||
use Typecho\Cookie;
|
||||
use Typecho\Db\Exception as DbException;
|
||||
use Typecho\Widget\Exception;
|
||||
use Typecho\Db\Query;
|
||||
use Typecho\Widget\Helper\PageNavigator\Box;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章管理列表组件
|
||||
@@ -18,46 +21,43 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
|
||||
class Admin extends Contents
|
||||
{
|
||||
/**
|
||||
* 用于计算数值的语句对象
|
||||
*
|
||||
* @access private
|
||||
* @var Typecho_Db_Query
|
||||
* @var Query
|
||||
*/
|
||||
private $_countSql;
|
||||
private $countSql;
|
||||
|
||||
/**
|
||||
* 所有文章个数
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_total = false;
|
||||
private $total = false;
|
||||
|
||||
/**
|
||||
* 当前页
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_currentPage;
|
||||
private $currentPage;
|
||||
|
||||
/**
|
||||
* 获取菜单标题
|
||||
*
|
||||
* @return string
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @throws Exception|DbException
|
||||
*/
|
||||
public function getMenuTitle()
|
||||
public function getMenuTitle(): string
|
||||
{
|
||||
if (isset($this->request->uid)) {
|
||||
return _t('%s的文章', $this->db->fetchObject($this->db->select('screenName')->from('table.users')
|
||||
->where('uid = ?', $this->request->filter('int')->uid))->screenName);
|
||||
}
|
||||
|
||||
throw new Typecho_Widget_Exception(_t('用户不存在'), 404);
|
||||
throw new Exception(_t('用户不存在'), 404);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,8 +65,9 @@ class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
|
||||
*
|
||||
* @param array $value
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function filter(array $value)
|
||||
public function filter(array $value): array
|
||||
{
|
||||
$value = parent::filter($value);
|
||||
|
||||
@@ -84,13 +85,12 @@ class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->parameter->setDefault('pageSize=20');
|
||||
$this->_currentPage = $this->request->get('page', 1);
|
||||
$this->currentPage = $this->request->get('page', 1);
|
||||
|
||||
/** 构建基础查询 */
|
||||
$select = $this->select();
|
||||
@@ -99,14 +99,14 @@ class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
|
||||
if (!$this->user->pass('editor', true)) {
|
||||
$select->where('table.contents.authorId = ?', $this->user->uid);
|
||||
} else {
|
||||
if ('on' == $this->request->__typecho_all_posts) {
|
||||
Typecho_Cookie::set('__typecho_all_posts', 'on');
|
||||
if ('on' == $this->request->_typecho_all_posts) {
|
||||
Cookie::set('__typecho_all_posts', 'on');
|
||||
} else {
|
||||
if ('off' == $this->request->__typecho_all_posts) {
|
||||
Typecho_Cookie::set('__typecho_all_posts', 'off');
|
||||
if ('off' == $this->request->_typecho_all_posts) {
|
||||
Cookie::set('__typecho_all_posts', 'off');
|
||||
}
|
||||
|
||||
if ('on' != Typecho_Cookie::get('__typecho_all_posts')) {
|
||||
if ('on' != Cookie::get('__typecho_all_posts')) {
|
||||
$select->where('table.contents.authorId = ?', isset($this->request->uid) ?
|
||||
$this->request->filter('int')->uid : $this->user->uid);
|
||||
}
|
||||
@@ -117,11 +117,19 @@ class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
|
||||
if ('draft' == $this->request->status) {
|
||||
$select->where('table.contents.type = ?', 'post_draft');
|
||||
} elseif ('waiting' == $this->request->status) {
|
||||
$select->where('(table.contents.type = ? OR table.contents.type = ?) AND table.contents.status = ?',
|
||||
'post', 'post_draft', 'waiting');
|
||||
$select->where(
|
||||
'(table.contents.type = ? OR table.contents.type = ?) AND table.contents.status = ?',
|
||||
'post',
|
||||
'post_draft',
|
||||
'waiting'
|
||||
);
|
||||
} else {
|
||||
$select->where('table.contents.type = ? OR (table.contents.type = ? AND table.contents.parent = ?)',
|
||||
'post', 'post_draft', 0);
|
||||
$select->where(
|
||||
'table.contents.type = ? OR (table.contents.type = ? AND table.contents.parent = ?)',
|
||||
'post',
|
||||
'post_draft',
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/** 过滤分类 */
|
||||
@@ -144,11 +152,11 @@ class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
|
||||
}
|
||||
|
||||
/** 给计算数目对象赋值,克隆对象 */
|
||||
$this->_countSql = clone $select;
|
||||
$this->countSql = clone $select;
|
||||
|
||||
/** 提交查询 */
|
||||
$select->order('table.contents.cid', Typecho_Db::SORT_DESC)
|
||||
->page($this->_currentPage, $this->parameter->pageSize);
|
||||
$select->order('table.contents.cid', Db::SORT_DESC)
|
||||
->page($this->currentPage, $this->parameter->pageSize);
|
||||
|
||||
$this->db->fetchAll($select, [$this, 'push']);
|
||||
}
|
||||
@@ -156,26 +164,30 @@ class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
|
||||
/**
|
||||
* 输出分页
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws DbException
|
||||
*/
|
||||
public function pageNav()
|
||||
{
|
||||
$query = $this->request->makeUriByRequest('page={page}');
|
||||
|
||||
/** 使用盒状分页 */
|
||||
$nav = new Typecho_Widget_Helper_PageNavigator_Box(false === $this->_total ? $this->_total = $this->size($this->_countSql) : $this->_total,
|
||||
$this->_currentPage, $this->parameter->pageSize, $query);
|
||||
$nav = new Box(
|
||||
false === $this->total ? $this->total = $this->size($this->countSql) : $this->total,
|
||||
$this->currentPage,
|
||||
$this->parameter->pageSize,
|
||||
$query
|
||||
);
|
||||
$nav->render('«', '»');
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前文章的草稿
|
||||
*
|
||||
* @access protected
|
||||
* @return bool
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function ___hasSaved()
|
||||
protected function ___hasSaved(): bool
|
||||
{
|
||||
if (in_array($this->type, ['post_draft', 'page_draft'])) {
|
||||
return true;
|
||||
@@ -183,8 +195,12 @@ class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
|
||||
|
||||
$savedPost = $this->db->fetchRow($this->db->select('cid', 'modified', 'status')
|
||||
->from('table.contents')
|
||||
->where('table.contents.parent = ? AND (table.contents.type = ? OR table.contents.type = ?)',
|
||||
$this->cid, 'post_draft', 'page_draft')
|
||||
->where(
|
||||
'table.contents.parent = ? AND (table.contents.type = ? OR table.contents.type = ?)',
|
||||
$this->cid,
|
||||
'post_draft',
|
||||
'page_draft'
|
||||
)
|
||||
->limit(1));
|
||||
|
||||
if ($savedPost) {
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 按日期归档列表组件
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Post;
|
||||
|
||||
use Typecho\Db;
|
||||
use Typecho\Router;
|
||||
use Typecho\Widget;
|
||||
use Widget\Options;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按日期归档列表组件
|
||||
@@ -17,47 +18,45 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
*/
|
||||
class Widget_Contents_Post_Date extends Typecho_Widget
|
||||
class Date extends Widget
|
||||
{
|
||||
/**
|
||||
* 全局选项
|
||||
*
|
||||
* @access protected
|
||||
* @var Widget_Options
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* 数据库对象
|
||||
*
|
||||
* @access protected
|
||||
* @var Typecho_Db
|
||||
* @var Db
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @throws Db\Exception
|
||||
* @throws Widget\Exception
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
|
||||
/** 初始化数据库 */
|
||||
$this->db = Typecho_Db::get();
|
||||
$this->db = Db::get();
|
||||
|
||||
/** 初始化常用组件 */
|
||||
$this->options = $this->widget('Widget_Options');
|
||||
$this->options = self::widget('\Widget\Options');
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
@@ -69,7 +68,7 @@ class Widget_Contents_Post_Date extends Typecho_Widget
|
||||
->where('type = ?', 'post')
|
||||
->where('table.contents.status = ?', 'publish')
|
||||
->where('table.contents.created < ?', $this->options->time)
|
||||
->order('table.contents.created', Typecho_Db::SORT_DESC));
|
||||
->order('table.contents.created', Db::SORT_DESC));
|
||||
|
||||
$offset = $this->options->timezone - $this->options->serverTimezone;
|
||||
$result = [];
|
||||
@@ -93,7 +92,11 @@ class Widget_Contents_Post_Date extends Typecho_Widget
|
||||
}
|
||||
|
||||
foreach ($result as $row) {
|
||||
$row['permalink'] = Typecho_Router::url('archive_' . $this->parameter->type, $row, $this->widget('Widget_Options')->index);
|
||||
$row['permalink'] = Router::url(
|
||||
'archive_' . $this->parameter->type,
|
||||
$row,
|
||||
self::widget('Widget_Options')->index
|
||||
);
|
||||
$this->push($row);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 编辑文章
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Post;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Config;
|
||||
use Typecho\Validate;
|
||||
use Typecho\Widget\Exception;
|
||||
use Typecho\Widget\Helper\Form\Element;
|
||||
use Typecho\Widget\Helper\Layout;
|
||||
use Widget\Base\Contents;
|
||||
use Widget\Base\Metas;
|
||||
use Widget\DoInterface;
|
||||
use Typecho\Db\Exception as DbException;
|
||||
use Typecho\Date as TypechoDate;
|
||||
use Widget\Notice;
|
||||
use Widget\Service;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章组件
|
||||
@@ -19,20 +29,19 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widget_Interface_Do
|
||||
class Edit extends Contents implements DoInterface
|
||||
{
|
||||
/**
|
||||
* 自定义字段的hook名称
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $themeCustomFieldsHook = 'themePostFields';
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @throws Exception|DbException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -47,13 +56,15 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
->limit(1), [$this, 'push']);
|
||||
|
||||
if ('post_draft' == $this->type && $this->parent) {
|
||||
$this->response->redirect(Typecho_Common::url('write-post.php?cid=' . $this->parent, $this->options->adminUrl));
|
||||
$this->response->redirect(
|
||||
Common::url('write-post.php?cid=' . $this->parent, $this->options->adminUrl)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$this->have()) {
|
||||
throw new Typecho_Widget_Exception(_t('文章不存在'), 404);
|
||||
} elseif ($this->have() && !$this->allow('edit')) {
|
||||
throw new Typecho_Widget_Exception(_t('没有编辑权限'), 403);
|
||||
throw new Exception(_t('文章不存在'), 404);
|
||||
} elseif (!$this->allow('edit')) {
|
||||
throw new Exception(_t('没有编辑权限'), 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,8 +73,8 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
* 获取文章权限
|
||||
*
|
||||
* @param mixed ...$permissions
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception|DbException
|
||||
*/
|
||||
public function allow(...$permissions): bool
|
||||
{
|
||||
@@ -87,16 +98,19 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 过滤堆栈
|
||||
*
|
||||
* @access public
|
||||
* @param array $value 每行的值
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function filter(array $value)
|
||||
public function filter(array $value): array
|
||||
{
|
||||
if ('post' == $value['type'] || 'page' == $value['type']) {
|
||||
$draft = $this->db->fetchRow($this->widget('Widget_Abstract_Contents')->select()
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?',
|
||||
$value['cid'], $value['type'] . '_draft')
|
||||
$draft = $this->db->fetchRow(self::widget(Contents::class)->select()
|
||||
->where(
|
||||
'table.contents.parent = ? AND table.contents.type = ?',
|
||||
$value['cid'],
|
||||
$value['type'] . '_draft'
|
||||
)
|
||||
->limit(1));
|
||||
|
||||
if (!empty($draft)) {
|
||||
@@ -109,7 +123,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
->select()->from('table.metas')
|
||||
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
|
||||
->where('table.relationships.cid = ?', $draft['cid'])
|
||||
->where('table.metas.type = ?', 'tag'), [$this->widget('Widget_Abstract_Metas'), 'filter']);
|
||||
->where('table.metas.type = ?', 'tag'), [self::widget(Metas::class), 'filter']);
|
||||
$draft['cid'] = $value['cid'];
|
||||
|
||||
return $draft;
|
||||
@@ -122,7 +136,6 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 输出文章发布日期
|
||||
*
|
||||
* @access public
|
||||
* @param string $format 日期格式
|
||||
* @return void
|
||||
*/
|
||||
@@ -138,10 +151,9 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 获取网页标题
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getMenuTitle()
|
||||
public function getMenuTitle(): string
|
||||
{
|
||||
return _t('编辑 %s', $this->title);
|
||||
}
|
||||
@@ -149,10 +161,9 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* getFieldItems
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
public function getFieldItems()
|
||||
public function getFieldItems(): array
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
@@ -181,15 +192,14 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* getDefaultFieldItems
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaultFieldItems()
|
||||
public function getDefaultFieldItems(): array
|
||||
{
|
||||
$defaultFields = [];
|
||||
$configFile = $this->options->themeFile($this->options->theme, 'functions.php');
|
||||
$layout = new Typecho_Widget_Helper_Layout();
|
||||
$fields = new Typecho_Config();
|
||||
$layout = new Layout();
|
||||
$fields = new Config();
|
||||
|
||||
if ($this->have()) {
|
||||
$fields = $this->fields;
|
||||
@@ -211,7 +221,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
|
||||
$items = $layout->getItems();
|
||||
foreach ($items as $item) {
|
||||
if ($item instanceof Typecho_Widget_Helper_Form_Element) {
|
||||
if ($item instanceof Element) {
|
||||
$name = $item->input->getAttribute('name');
|
||||
|
||||
$isFieldReadOnly = $this->pluginHandle('Widget_Abstract_Contents')
|
||||
@@ -234,7 +244,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
|
||||
$elements = $item->container->getItems();
|
||||
array_shift($elements);
|
||||
$div = new Typecho_Widget_Helper_Layout('div');
|
||||
$div = new Layout('div');
|
||||
|
||||
foreach ($elements as $el) {
|
||||
$div->addItem($el);
|
||||
@@ -249,14 +259,19 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
|
||||
/**
|
||||
* 发布文章
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function writePost()
|
||||
{
|
||||
$contents = $this->request->from('password', 'allowComment',
|
||||
'allowPing', 'allowFeed', 'slug', 'tags', 'text', 'visibility');
|
||||
$contents = $this->request->from(
|
||||
'password',
|
||||
'allowComment',
|
||||
'allowPing',
|
||||
'allowFeed',
|
||||
'slug',
|
||||
'tags',
|
||||
'text',
|
||||
'visibility'
|
||||
);
|
||||
|
||||
$contents['category'] = $this->request->getArray('category');
|
||||
$contents['title'] = $this->request->get('title', _t('未命名文档'));
|
||||
@@ -278,21 +293,21 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
|
||||
/** 发送ping */
|
||||
$trackback = array_unique(preg_split("/(\r|\n|\r\n)/", trim($this->request->trackback)));
|
||||
$this->widget('Widget_Service')->sendPing($this->cid, $trackback);
|
||||
self::widget(Service::class)->sendPing($this->cid, $trackback);
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set('post' == $this->type ?
|
||||
self::widget(Notice::class)->set('post' == $this->type ?
|
||||
_t('文章 "<a href="%s">%s</a>" 已经发布', $this->permalink, $this->title) :
|
||||
_t('文章 "%s" 等待审核', $this->title), 'success');
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->theId);
|
||||
self::widget(Notice::class)->highlight($this->theId);
|
||||
|
||||
/** 获取页面偏移 */
|
||||
$pageQuery = $this->getPageOffsetQuery($this->cid);
|
||||
|
||||
/** 页面跳转 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-posts.php?' . $pageQuery, $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-posts.php?' . $pageQuery, $this->options->adminUrl));
|
||||
} else {
|
||||
/** 保存文章 */
|
||||
$contents['type'] = 'post_draft';
|
||||
@@ -302,10 +317,10 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
$this->pluginHandle()->finishSave($contents, $this);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->cid);
|
||||
self::widget(Notice::class)->highlight($this->cid);
|
||||
|
||||
if ($this->request->isAjax()) {
|
||||
$created = new Typecho_Date();
|
||||
$created = new TypechoDate();
|
||||
$this->response->throwJson([
|
||||
'success' => 1,
|
||||
'time' => $created->format('H:i:s A'),
|
||||
@@ -314,10 +329,10 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
]);
|
||||
} else {
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('草稿 "%s" 已经被保存', $this->title), 'success');
|
||||
self::widget(Notice::class)->set(_t('草稿 "%s" 已经被保存', $this->title), 'success');
|
||||
|
||||
/** 返回原页面 */
|
||||
$this->response->redirect(Typecho_Common::url('write-post.php?cid=' . $this->cid, $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('write-post.php?cid=' . $this->cid, $this->options->adminUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,10 +340,9 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 根据提交值获取created字段值
|
||||
*
|
||||
* @access protected
|
||||
* @return integer
|
||||
*/
|
||||
protected function getCreated()
|
||||
protected function getCreated(): int
|
||||
{
|
||||
$created = $this->options->time;
|
||||
if (!empty($this->request->created)) {
|
||||
@@ -350,7 +364,8 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
$month = intval($this->request->month);
|
||||
$day = intval($this->request->day);
|
||||
|
||||
$created = mktime($hour, $min, $second, $month, $day, $year) - $this->options->timezone + $this->options->serverTimezone;
|
||||
$created = mktime($hour, $min, $second, $month, $day, $year)
|
||||
- $this->options->timezone + $this->options->serverTimezone;
|
||||
} elseif ($this->have() && $this->created > 0) {
|
||||
//如果是修改文章
|
||||
$created = $this->created;
|
||||
@@ -365,9 +380,8 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 发布内容
|
||||
*
|
||||
* @access protected
|
||||
* @param array $contents 内容结构
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function publish(array $contents)
|
||||
{
|
||||
@@ -375,7 +389,9 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
if ($this->user->pass('editor', true)) {
|
||||
if (empty($contents['visibility'])) {
|
||||
$contents['status'] = 'publish';
|
||||
} elseif ('password' == $contents['visibility'] || !in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden'])) {
|
||||
} elseif (
|
||||
!in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden'])
|
||||
) {
|
||||
if (empty($contents['password']) || 'password' != $contents['visibility']) {
|
||||
$contents['password'] = '';
|
||||
}
|
||||
@@ -421,8 +437,13 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
if ($realId > 0) {
|
||||
/** 插入分类 */
|
||||
if (array_key_exists('category', $contents)) {
|
||||
$this->setCategories($realId, !empty($contents['category']) && is_array($contents['category']) ?
|
||||
$contents['category'] : [$this->options->defaultCategory], !$isDraftToPublish && $isBeforePublish, $isAfterPublish);
|
||||
$this->setCategories(
|
||||
$realId,
|
||||
!empty($contents['category']) && is_array($contents['category'])
|
||||
? $contents['category'] : [$this->options->defaultCategory],
|
||||
!$isDraftToPublish && $isBeforePublish,
|
||||
$isAfterPublish
|
||||
);
|
||||
}
|
||||
|
||||
/** 插入标签 */
|
||||
@@ -443,9 +464,8 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 删除草稿
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $cid 草稿id
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function deleteDraft($cid)
|
||||
{
|
||||
@@ -461,24 +481,27 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 设置分类
|
||||
*
|
||||
* @access public
|
||||
* @param integer $cid 内容id
|
||||
* @param array $categories 分类id的集合数组
|
||||
* @param boolean $beforeCount 是否参与计数
|
||||
* @param boolean $afterCount 是否参与计数
|
||||
* @return integer
|
||||
* @throws DbException
|
||||
*/
|
||||
public function setCategories($cid, array $categories, $beforeCount = true, $afterCount = true)
|
||||
public function setCategories(int $cid, array $categories, bool $beforeCount = true, bool $afterCount = true)
|
||||
{
|
||||
$categories = array_unique(array_map('trim', $categories));
|
||||
|
||||
/** 取出已有category */
|
||||
$existCategories = array_column($this->db->fetchAll(
|
||||
$this->db->select('table.metas.mid')
|
||||
->from('table.metas')
|
||||
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
|
||||
->where('table.relationships.cid = ?', $cid)
|
||||
->where('table.metas.type = ?', 'category')), 'mid');
|
||||
$existCategories = array_column(
|
||||
$this->db->fetchAll(
|
||||
$this->db->select('table.metas.mid')
|
||||
->from('table.metas')
|
||||
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
|
||||
->where('table.relationships.cid = ?', $cid)
|
||||
->where('table.metas.type = ?', 'category')
|
||||
),
|
||||
'mid'
|
||||
);
|
||||
|
||||
/** 删除已有category */
|
||||
if ($existCategories) {
|
||||
@@ -499,10 +522,14 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
if ($categories) {
|
||||
foreach ($categories as $category) {
|
||||
/** 如果分类不存在 */
|
||||
if (!$this->db->fetchRow($this->db->select('mid')
|
||||
->from('table.metas')
|
||||
->where('mid = ?', $category)
|
||||
->limit(1))) {
|
||||
if (
|
||||
!$this->db->fetchRow(
|
||||
$this->db->select('mid')
|
||||
->from('table.metas')
|
||||
->where('mid = ?', $category)
|
||||
->limit(1)
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -524,26 +551,29 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 设置内容标签
|
||||
*
|
||||
* @access public
|
||||
* @param integer $cid
|
||||
* @param string $tags
|
||||
* @param boolean $beforeCount 是否参与计数
|
||||
* @param boolean $afterCount 是否参与计数
|
||||
* @return string
|
||||
* @throws DbException
|
||||
*/
|
||||
public function setTags($cid, $tags, $beforeCount = true, $afterCount = true)
|
||||
public function setTags(int $cid, string $tags, bool $beforeCount = true, bool $afterCount = true)
|
||||
{
|
||||
$tags = str_replace(',', ',', $tags);
|
||||
$tags = array_unique(array_map('trim', explode(',', $tags)));
|
||||
$tags = array_filter($tags, ['Typecho_Validate', 'xssCheck']);
|
||||
$tags = array_filter($tags, [Validate::class, 'xssCheck']);
|
||||
|
||||
/** 取出已有tag */
|
||||
$existTags = array_column($this->db->fetchAll(
|
||||
$this->db->select('table.metas.mid')
|
||||
$existTags = array_column(
|
||||
$this->db->fetchAll(
|
||||
$this->db->select('table.metas.mid')
|
||||
->from('table.metas')
|
||||
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
|
||||
->where('table.relationships.cid = ?', $cid)
|
||||
->where('table.metas.type = ?', 'tag')), 'mid');
|
||||
->where('table.metas.type = ?', 'tag')
|
||||
),
|
||||
'mid'
|
||||
);
|
||||
|
||||
/** 删除已有tag */
|
||||
if ($existTags) {
|
||||
@@ -565,7 +595,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
}
|
||||
|
||||
/** 取出插入tag */
|
||||
$insertTags = $this->widget('Widget_Abstract_Metas')->scanTags($tags);
|
||||
$insertTags = self::widget(Metas::class)->scanTags($tags);
|
||||
|
||||
/** 插入tag */
|
||||
if ($insertTags) {
|
||||
@@ -592,11 +622,10 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 同步附件
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $cid 内容id
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function attach($cid)
|
||||
protected function attach(int $cid)
|
||||
{
|
||||
$attachments = $this->request->getArray('attachment');
|
||||
if (!empty($attachments)) {
|
||||
@@ -612,10 +641,9 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* getFields
|
||||
*
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function getFields()
|
||||
protected function getFields(): array
|
||||
{
|
||||
$fields = [];
|
||||
$fieldNames = $this->request->getArray('fieldNames');
|
||||
@@ -648,23 +676,27 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 获取页面偏移的URL Query
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $cid 文章id
|
||||
* @param string $status 状态
|
||||
* @param string|null $status 状态
|
||||
* @return string
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function getPageOffsetQuery($cid, $status = null)
|
||||
protected function getPageOffsetQuery(int $cid, ?string $status = null): string
|
||||
{
|
||||
return 'page=' . $this->getPageOffset('cid', $cid, 'post', $status,
|
||||
'on' == $this->request->__typecho_all_posts ? 0 : $this->user->uid);
|
||||
return 'page=' . $this->getPageOffset(
|
||||
'cid',
|
||||
$cid,
|
||||
'post',
|
||||
$status,
|
||||
'on' == $this->request->__typecho_all_posts ? 0 : $this->user->uid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存内容
|
||||
*
|
||||
* @access protected
|
||||
* @param array $contents 内容结构
|
||||
* @return void
|
||||
* @throws DbException|Exception
|
||||
*/
|
||||
protected function save(array $contents)
|
||||
{
|
||||
@@ -672,7 +704,9 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
if ($this->user->pass('editor', true)) {
|
||||
if (empty($contents['visibility'])) {
|
||||
$contents['status'] = 'publish';
|
||||
} elseif ('password' == $contents['visibility'] || !in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden'])) {
|
||||
} elseif (
|
||||
!in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden'])
|
||||
) {
|
||||
if (empty($contents['password']) || 'password' != $contents['visibility']) {
|
||||
$contents['password'] = '';
|
||||
}
|
||||
@@ -706,13 +740,14 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
$realId = $this->insert($contents);
|
||||
|
||||
if (!$this->have()) {
|
||||
$this->db->fetchRow($this->select()->where('table.contents.cid = ?', $realId)->limit(1), [$this, 'push']);
|
||||
$this->db->fetchRow(
|
||||
$this->select()->where('table.contents.cid = ?', $realId)->limit(1),
|
||||
[$this, 'push']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($realId > 0) {
|
||||
//$this->db->fetchRow($this->select()->where('table.contents.cid = ?', $realId)->limit(1), array($this, 'push'));
|
||||
|
||||
/** 插入分类 */
|
||||
if (array_key_exists('category', $contents)) {
|
||||
$this->setCategories($realId, !empty($contents['category']) && is_array($contents['category']) ?
|
||||
@@ -735,8 +770,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 标记文章
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
public function markPost()
|
||||
{
|
||||
@@ -763,8 +797,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
$postObject = $this->db->fetchObject($this->db->select('status', 'type')
|
||||
->from('table.contents')->where('cid = ? AND (type = ? OR type = ?)', $post, 'post', 'post_draft'));
|
||||
|
||||
if ($this->isWriteable(clone $condition) &&
|
||||
count((array)$postObject)) {
|
||||
if ($this->isWriteable(clone $condition) && count((array)$postObject)) {
|
||||
|
||||
/** 标记状态 */
|
||||
$this->db->query($condition->update('table.contents')->rows(['status' => $status]));
|
||||
@@ -780,7 +813,9 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
}
|
||||
|
||||
if (!empty($op)) {
|
||||
$metas = $this->db->fetchAll($this->db->select()->from('table.relationships')->where('cid = ?', $post));
|
||||
$metas = $this->db->fetchAll(
|
||||
$this->db->select()->from('table.relationships')->where('cid = ?', $post)
|
||||
);
|
||||
foreach ($metas as $meta) {
|
||||
$this->db->query($this->db->update('table.metas')
|
||||
->expression('count', 'count ' . $op . ' 1')
|
||||
@@ -792,8 +827,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
// 处理草稿
|
||||
$draft = $this->db->fetchRow($this->db->select('cid')
|
||||
->from('table.contents')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?',
|
||||
$post, 'post_draft')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?', $post, 'post_draft')
|
||||
->limit(1));
|
||||
|
||||
if (!empty($draft)) {
|
||||
@@ -804,15 +838,18 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
// 完成标记插件接口
|
||||
$this->pluginHandle()->finishMark($status, $post, $this);
|
||||
|
||||
$markCount ++;
|
||||
$markCount++;
|
||||
}
|
||||
|
||||
unset($condition);
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($markCount > 0 ? _t('文章已经被标记为<strong>%s</strong>', $statusList[$status]) : _t('没有文章被标记'),
|
||||
$markCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$markCount > 0 ? _t('文章已经被标记为<strong>%s</strong>', $statusList[$status]) : _t('没有文章被标记'),
|
||||
$markCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -821,8 +858,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 删除文章
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
public function deletePost()
|
||||
{
|
||||
@@ -837,9 +873,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
$postObject = $this->db->fetchObject($this->db->select('status', 'type')
|
||||
->from('table.contents')->where('cid = ? AND (type = ? OR type = ?)', $post, 'post', 'post_draft'));
|
||||
|
||||
if ($this->isWriteable(clone $condition) &&
|
||||
count((array)$postObject) &&
|
||||
$this->delete($condition)) {
|
||||
if ($this->isWriteable(clone $condition) && count((array)$postObject) && $this->delete($condition)) {
|
||||
|
||||
/** 删除分类 */
|
||||
$this->setCategories($post, [], 'publish' == $postObject->status
|
||||
@@ -859,8 +893,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/** 删除草稿 */
|
||||
$draft = $this->db->fetchRow($this->db->select('cid')
|
||||
->from('table.contents')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?',
|
||||
$post, 'post_draft')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?', $post, 'post_draft')
|
||||
->limit(1));
|
||||
|
||||
/** 删除自定义字段 */
|
||||
@@ -874,7 +907,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
// 完成删除插件接口
|
||||
$this->pluginHandle()->finishDelete($post, $this);
|
||||
|
||||
$deleteCount ++;
|
||||
$deleteCount++;
|
||||
}
|
||||
|
||||
unset($condition);
|
||||
@@ -882,12 +915,14 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
|
||||
// 清理标签
|
||||
if ($deleteCount > 0) {
|
||||
$this->widget('Widget_Abstract_Metas')->clearTags();
|
||||
self::widget(Metas::class)->clearTags();
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('文章已经被删除') : _t('没有文章被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)->set(
|
||||
$deleteCount > 0 ? _t('文章已经被删除') : _t('没有文章被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -896,9 +931,8 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 取消附件关联
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $cid 内容id
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function unAttach($cid)
|
||||
{
|
||||
@@ -909,8 +943,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 删除文章所属草稿
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
public function deletePostDraft()
|
||||
{
|
||||
@@ -921,20 +954,22 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/** 删除草稿 */
|
||||
$draft = $this->db->fetchRow($this->db->select('cid')
|
||||
->from('table.contents')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?',
|
||||
$post, 'post_draft')
|
||||
->where('table.contents.parent = ? AND table.contents.type = ?', $post, 'post_draft')
|
||||
->limit(1));
|
||||
|
||||
if ($draft) {
|
||||
$this->deleteDraft($draft['cid']);
|
||||
$this->deleteFields($draft['cid']);
|
||||
$deleteCount ++;
|
||||
$deleteCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('草稿已经被删除') : _t('没有草稿被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set(
|
||||
$deleteCount > 0 ? _t('草稿已经被删除') : _t('没有草稿被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 返回原网页 */
|
||||
$this->response->goBack();
|
||||
@@ -942,9 +977,6 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
|
||||
/**
|
||||
* 绑定动作
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function action()
|
||||
{
|
||||
@@ -960,17 +992,17 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 将tags取出
|
||||
*
|
||||
* @access protected
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function ___tags()
|
||||
protected function ___tags(): array
|
||||
{
|
||||
if ($this->have()) {
|
||||
return $this->db->fetchAll($this->db
|
||||
->select()->from('table.metas')
|
||||
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
|
||||
->where('table.relationships.cid = ?', $this->cid)
|
||||
->where('table.metas.type = ?', 'tag'), [$this->widget('Widget_Abstract_Metas'), 'filter']);
|
||||
->where('table.metas.type = ?', 'tag'), [self::widget(Metas::class), 'filter']);
|
||||
}
|
||||
|
||||
return [];
|
||||
@@ -979,19 +1011,18 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
/**
|
||||
* 获取当前时间
|
||||
*
|
||||
* @access protected
|
||||
* @return Typecho_Date
|
||||
* @return TypechoDate
|
||||
*/
|
||||
protected function ___date()
|
||||
protected function ___date(): TypechoDate
|
||||
{
|
||||
return new Typecho_Date();
|
||||
return new TypechoDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前文章的草稿
|
||||
*
|
||||
* @access protected
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function ___draft()
|
||||
{
|
||||
@@ -999,10 +1030,14 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
if ('post_draft' == $this->type) {
|
||||
return $this->row;
|
||||
} else {
|
||||
return $this->db->fetchRow($this->widget('Widget_Abstract_Contents')->select()
|
||||
->where('table.contents.parent = ? AND (table.contents.type = ? OR table.contents.type = ?)',
|
||||
$this->cid, 'post_draft', 'page_draft')
|
||||
->limit(1), [$this->widget('Widget_Abstract_Contents'), 'filter']);
|
||||
return $this->db->fetchRow(self::widget(Contents::class)->select()
|
||||
->where(
|
||||
'table.contents.parent = ? AND (table.contents.type = ? OR table.contents.type = ?)',
|
||||
$this->cid,
|
||||
'post_draft',
|
||||
'page_draft'
|
||||
)
|
||||
->limit(1), [self::widget(Contents::class), 'filter']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 最新文章
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Post;
|
||||
|
||||
use Typecho\Db;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最新评论组件
|
||||
@@ -18,13 +17,12 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Post_Recent extends Widget_Abstract_Contents
|
||||
class Recent extends Contents
|
||||
{
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -34,7 +32,7 @@ class Widget_Contents_Post_Recent extends Widget_Abstract_Contents
|
||||
->where('table.contents.status = ?', 'publish')
|
||||
->where('table.contents.created < ?', $this->options->time)
|
||||
->where('table.contents.type = ?', 'post')
|
||||
->order('table.contents.created', Typecho_Db::SORT_DESC)
|
||||
->order('table.contents.created', Db::SORT_DESC)
|
||||
->limit($this->parameter->pageSize), [$this, 'push']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 相关内容
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents;
|
||||
|
||||
use Typecho\Db;
|
||||
use Typecho\Db\Query;
|
||||
use Typecho\Db\Exception;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 相关内容组件(根据标签关联)
|
||||
@@ -19,13 +20,12 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Related extends Widget_Abstract_Contents
|
||||
class Related extends Contents
|
||||
{
|
||||
/**
|
||||
* 执行函数,初始化数据
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -41,7 +41,7 @@ class Widget_Contents_Related extends Widget_Abstract_Contents
|
||||
->where('table.contents.password IS NULL')
|
||||
->where('table.contents.created < ?', $this->options->time)
|
||||
->where('table.contents.type = ?', $this->parameter->type)
|
||||
->order('table.contents.created', Typecho_Db::SORT_DESC)
|
||||
->order('table.contents.created', Db::SORT_DESC)
|
||||
->limit($this->parameter->limit), [$this, 'push']);
|
||||
}
|
||||
}
|
||||
@@ -49,14 +49,29 @@ class Widget_Contents_Related extends Widget_Abstract_Contents
|
||||
/**
|
||||
* 获取查询对象
|
||||
*
|
||||
* @access public
|
||||
* @return Typecho_Db_Query
|
||||
* @return Query
|
||||
* @throws Exception
|
||||
*/
|
||||
public function select()
|
||||
public function select(): Query
|
||||
{
|
||||
return $this->db->select('DISTINCT table.contents.cid', 'table.contents.title', 'table.contents.slug', 'table.contents.created', 'table.contents.authorId',
|
||||
'table.contents.modified', 'table.contents.type', 'table.contents.status', 'table.contents.text', 'table.contents.commentsNum', 'table.contents.order',
|
||||
'table.contents.template', 'table.contents.password', 'table.contents.allowComment', 'table.contents.allowPing', 'table.contents.allowFeed')
|
||||
return $this->db->select(
|
||||
'DISTINCT table.contents.cid',
|
||||
'table.contents.title',
|
||||
'table.contents.slug',
|
||||
'table.contents.created',
|
||||
'table.contents.authorId',
|
||||
'table.contents.modified',
|
||||
'table.contents.type',
|
||||
'table.contents.status',
|
||||
'table.contents.text',
|
||||
'table.contents.commentsNum',
|
||||
'table.contents.order',
|
||||
'table.contents.template',
|
||||
'table.contents.password',
|
||||
'table.contents.allowComment',
|
||||
'table.contents.allowPing',
|
||||
'table.contents.allowFeed'
|
||||
)
|
||||
->from('table.contents');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 相关内容
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Contents\Related;
|
||||
|
||||
use Typecho\Db;
|
||||
use Typecho\Db\Exception;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 相关内容组件(根据作者关联)
|
||||
@@ -19,13 +19,12 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Contents_Related_Author extends Widget_Abstract_Contents
|
||||
class Author extends Contents
|
||||
{
|
||||
/**
|
||||
* 执行函数,初始化数据
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -39,7 +38,7 @@ class Widget_Contents_Related_Author extends Widget_Abstract_Contents
|
||||
->where('table.contents.password IS NULL')
|
||||
->where('table.contents.created < ?', $this->options->time)
|
||||
->where('table.contents.type = ?', $this->parameter->type)
|
||||
->order('table.contents.created', Typecho_Db::SORT_DESC)
|
||||
->order('table.contents.created', Db::SORT_DESC)
|
||||
->limit($this->parameter->limit), [$this, 'push']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class Widget_Do extends Typecho_Widget
|
||||
$action = $this->request->action;
|
||||
|
||||
/** 判断是否为plugin */
|
||||
$actionTable = array_merge($this->map, unserialize($this->widget('Widget_Options')->actionTable));
|
||||
$actionTable = array_merge($this->map, unserialize(self::widget('Widget_Options')->actionTable));
|
||||
|
||||
if (isset($actionTable[$action])) {
|
||||
$widgetName = $actionTable[$action];
|
||||
@@ -63,7 +63,7 @@ class Widget_Do extends Typecho_Widget
|
||||
if (isset($widgetName) && class_exists($widgetName)) {
|
||||
$reflectionWidget = new ReflectionClass($widgetName);
|
||||
if ($reflectionWidget->implementsInterface('Widget_Interface_Do')) {
|
||||
$this->widget($widgetName)->action();
|
||||
self::widget($widgetName)->action();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
14
var/Widget/DoInterface.php
Normal file
14
var/Widget/DoInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Widget;
|
||||
|
||||
/**
|
||||
* 可以被Widget_Do调用的接口
|
||||
*/
|
||||
interface DoInterface
|
||||
{
|
||||
/**
|
||||
* 接口需要实现的入口函数
|
||||
*/
|
||||
public function action();
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class ExceptionHandle extends Widget_Archive
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->widget('Widget_Archive@404', 'type=404')->render();
|
||||
self::widget('Widget_Archive@404', 'type=404')->render();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Init extends Widget
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Widget\Exception|Db\Exception
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -42,11 +42,13 @@ class Init extends Widget
|
||||
'Widget_Abstract_Metas' => '\Widget\Base\Metas',
|
||||
'Widget_Abstract_Options' => '\Widget\Base\Options',
|
||||
'Widget_Abstract_Users' => '\Widget\Base\Users',
|
||||
'Widget_Metas_Category_List' => '\Widget\Metas\Category\Rows'
|
||||
'Widget_Metas_Category_List' => '\Widget\Metas\Category\Rows',
|
||||
'Widget_Contents_Page_List' => '\Widget\Contents\Page\Rows',
|
||||
'Widget_Interface_Do' => '\Widget\DoInterface'
|
||||
]);
|
||||
|
||||
/** 对变量赋值 */
|
||||
$options = $this->widget('Widget_Options');
|
||||
$options = self::widget(Options::class);
|
||||
|
||||
/** 检查安装状态 */
|
||||
if (!defined('__TYPECHO_INSTALL__') && !$options->installed) {
|
||||
@@ -102,7 +104,7 @@ class Init extends Widget
|
||||
Date::setTimezoneOffset($options->timezone);
|
||||
|
||||
/** 开始会话, 减小负载只针对后台打开session支持 */
|
||||
if (!defined('__TYPECHO_INSTALL__') && $this->widget('Widget_User')->hasLogin()) {
|
||||
if (!defined('__TYPECHO_INSTALL__') && self::widget(User::class)->hasLogin()) {
|
||||
@session_start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 可以被Widget_Do调用的接口
|
||||
*
|
||||
* @package Widget
|
||||
* @version $id$
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @author qining <magike.net@gmail.com>
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
interface Widget_Interface_Do
|
||||
{
|
||||
/**
|
||||
* 接口需要实现的入口函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function action();
|
||||
}
|
||||
@@ -47,7 +47,7 @@ class Widget_Login extends Widget_Abstract_Users implements Widget_Interface_Do
|
||||
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($error);
|
||||
self::widget('Widget_Notice')->set($error);
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class Widget_Login extends Widget_Abstract_Users implements Widget_Interface_Do
|
||||
$this->request->password, 1 == $this->request->remember);
|
||||
|
||||
Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
|
||||
$this->widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error');
|
||||
self::widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error');
|
||||
$this->response->goBack('?referer=' . urlencode($this->request->referer));
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ class Widget_Menu extends Typecho_Widget
|
||||
parent::__construct($request, $response, $params);
|
||||
|
||||
/** 初始化常用组件 */
|
||||
$this->options = $this->widget('Widget_Options');
|
||||
$this->user = $this->widget('Widget_User');
|
||||
$this->options = self::widget('Widget_Options');
|
||||
$this->user = self::widget('Widget_User');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
|
||||
namespace Widget\Metas\Category;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Db;
|
||||
use Typecho\Widget\Exception;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget_Metas_Category_Admin
|
||||
@@ -9,13 +18,12 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @author Joyqi <magike.net@gmail.com>
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Metas_Category_Admin extends Widget_Metas_Category_List
|
||||
class Admin extends Rows
|
||||
{
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -23,14 +31,15 @@ class Widget_Metas_Category_Admin extends Widget_Metas_Category_List
|
||||
$select->where('parent = ?', $this->request->parent ? $this->request->parent : 0);
|
||||
|
||||
$this->stack = $this->getCategories(array_column(
|
||||
$this->db->fetchAll($select->order('table.metas.order', Typecho_Db::SORT_ASC)), 'mid'));
|
||||
$this->db->fetchAll($select->order('table.metas.order', Db::SORT_ASC)),
|
||||
'mid'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 向上的返回链接
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function backLink()
|
||||
{
|
||||
@@ -43,9 +52,11 @@ class Widget_Metas_Category_Admin extends Widget_Metas_Category_List
|
||||
->where('type = ? AND mid = ?', 'category', $category['parent']));
|
||||
|
||||
if ($parent) {
|
||||
echo '<a href="' . Typecho_Common::url('manage-categories.php?parent=' . $parent['mid'], $this->options->adminUrl) . '">';
|
||||
echo '<a href="'
|
||||
. Common::url('manage-categories.php?parent=' . $parent['mid'], $this->options->adminUrl)
|
||||
. '">';
|
||||
} else {
|
||||
echo '<a href="' . Typecho_Common::url('manage-categories.php', $this->options->adminUrl) . '">';
|
||||
echo '<a href="' . Common::url('manage-categories.php', $this->options->adminUrl) . '">';
|
||||
}
|
||||
|
||||
echo '« ';
|
||||
@@ -58,10 +69,10 @@ class Widget_Metas_Category_Admin extends Widget_Metas_Category_List
|
||||
/**
|
||||
* 获取菜单标题
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @return string|null
|
||||
* @throws Db\Exception|Exception
|
||||
*/
|
||||
public function getMenuTitle()
|
||||
public function getMenuTitle(): ?string
|
||||
{
|
||||
if (isset($this->request->parent)) {
|
||||
$category = $this->db->fetchRow($this->select()
|
||||
@@ -71,19 +82,18 @@ class Widget_Metas_Category_Admin extends Widget_Metas_Category_List
|
||||
return _t('管理 %s 的子分类', $category['name']);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new Typecho_Widget_Exception(_t('分类不存在'), 404);
|
||||
throw new Exception(_t('分类不存在'), 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单标题
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getAddLink()
|
||||
public function getAddLink(): string
|
||||
{
|
||||
if (isset($this->request->parent)) {
|
||||
return 'category.php?parent=' . $this->request->filter('int')->parent;
|
||||
@@ -92,4 +102,3 @@ class Widget_Metas_Category_Admin extends Widget_Metas_Category_List
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 编辑分类
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Metas\Category;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Db\Exception;
|
||||
use Typecho\Validate;
|
||||
use Typecho\Widget\Helper\Form;
|
||||
use Widget\Base\Metas;
|
||||
use Widget\DoInterface;
|
||||
use Widget\Notice;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑分类组件
|
||||
@@ -18,13 +22,10 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget_Interface_Do
|
||||
class Edit extends Metas implements DoInterface
|
||||
{
|
||||
/**
|
||||
* 入口函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -35,28 +36,28 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
/**
|
||||
* 判断分类是否存在
|
||||
*
|
||||
* @access public
|
||||
* @param integer $mid 分类主键
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function categoryExists($mid)
|
||||
public function categoryExists(int $mid): bool
|
||||
{
|
||||
$category = $this->db->fetchRow($this->db->select()
|
||||
->from('table.metas')
|
||||
->where('type = ?', 'category')
|
||||
->where('mid = ?', $mid)->limit(1));
|
||||
|
||||
return $category ? true : false;
|
||||
return (bool)$category;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断分类名称是否存在
|
||||
*
|
||||
* @access public
|
||||
* @param string $name 分类名称
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function nameExists($name)
|
||||
public function nameExists(string $name): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.metas')
|
||||
@@ -69,20 +70,19 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
}
|
||||
|
||||
$category = $this->db->fetchRow($select);
|
||||
return $category ? false : true;
|
||||
return !$category;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断分类名转换到缩略名后是否合法
|
||||
*
|
||||
* @access public
|
||||
* @param string $name 分类名
|
||||
* @return boolean
|
||||
*/
|
||||
public function nameToSlug($name)
|
||||
public function nameToSlug(string $name): bool
|
||||
{
|
||||
if (empty($this->request->slug)) {
|
||||
$slug = Typecho_Common::slugName($name);
|
||||
$slug = Common::slugName($name);
|
||||
if (empty($slug) || !$this->slugExists($name)) {
|
||||
return false;
|
||||
}
|
||||
@@ -94,16 +94,16 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
/**
|
||||
* 判断分类缩略名是否存在
|
||||
*
|
||||
* @access public
|
||||
* @param string $slug 缩略名
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function slugExists($slug)
|
||||
public function slugExists(string $slug): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.metas')
|
||||
->where('type = ?', 'category')
|
||||
->where('slug = ?', Typecho_Common::slugName($slug))
|
||||
->where('slug = ?', Common::slugName($slug))
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->mid) {
|
||||
@@ -111,14 +111,13 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
}
|
||||
|
||||
$category = $this->db->fetchRow($select);
|
||||
return $category ? false : true;
|
||||
return !$category;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加分类
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function insertCategory()
|
||||
{
|
||||
@@ -129,7 +128,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
/** 取出数据 */
|
||||
$category = $this->request->from('name', 'slug', 'description', 'parent');
|
||||
|
||||
$category['slug'] = Typecho_Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
|
||||
$category['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
|
||||
$category['type'] = 'category';
|
||||
$category['order'] = $this->getMaxOrder('category', $category['parent']) + 1;
|
||||
|
||||
@@ -138,67 +137,85 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
$this->push($category);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->theId);
|
||||
self::widget(Notice::class)->highlight($this->theId);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('分类 <a href="%s">%s</a> 已经被增加',
|
||||
$this->permalink, $this->name), 'success');
|
||||
self::widget(Notice::class)->set(
|
||||
_t('分类 <a href="%s">%s</a> 已经被增加', $this->permalink, $this->name),
|
||||
'success'
|
||||
);
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-categories.php'
|
||||
$this->response->redirect(Common::url('manage-categories.php'
|
||||
. ($category['parent'] ? '?parent=' . $category['parent'] : ''), $this->options->adminUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成表单
|
||||
*
|
||||
* @access public
|
||||
* @param string $action 表单动作
|
||||
* @return Typecho_Widget_Helper_Form_Element
|
||||
* @param string|null $action 表单动作
|
||||
* @return Form
|
||||
* @throws Exception
|
||||
*/
|
||||
public function form($action = null)
|
||||
public function form(?string $action = null): Form
|
||||
{
|
||||
/** 构建表格 */
|
||||
$form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/metas-category-edit'),
|
||||
Typecho_Widget_Helper_Form::POST_METHOD);
|
||||
$form = new Form($this->security->getIndex('/action/metas-category-edit'), Form::POST_METHOD);
|
||||
|
||||
/** 分类名称 */
|
||||
$name = new Typecho_Widget_Helper_Form_Element_Text('name', null, null, _t('分类名称') . ' *');
|
||||
$name = new Form\Element\Text('name', null, null, _t('分类名称') . ' *');
|
||||
$form->addInput($name);
|
||||
|
||||
/** 分类缩略名 */
|
||||
$slug = new Typecho_Widget_Helper_Form_Element_Text('slug', null, null, _t('分类缩略名'),
|
||||
_t('分类缩略名用于创建友好的链接形式, 建议使用字母, 数字, 下划线和横杠.'));
|
||||
$slug = new Form\Element\Text(
|
||||
'slug',
|
||||
null,
|
||||
null,
|
||||
_t('分类缩略名'),
|
||||
_t('分类缩略名用于创建友好的链接形式, 建议使用字母, 数字, 下划线和横杠.')
|
||||
);
|
||||
$form->addInput($slug);
|
||||
|
||||
/** 父级分类 */
|
||||
$options = [0 => _t('不选择')];
|
||||
$parents = $this->widget('Widget_Metas_Category_List@options',
|
||||
(isset($this->request->mid) ? 'ignore=' . $this->request->mid : ''));
|
||||
$parents = self::widget(
|
||||
Rows::class . '@options',
|
||||
(isset($this->request->mid) ? 'ignore=' . $this->request->mid : '')
|
||||
);
|
||||
|
||||
while ($parents->next()) {
|
||||
$options[$parents->mid] = str_repeat(' ', $parents->levels) . $parents->name;
|
||||
}
|
||||
|
||||
$parent = new Typecho_Widget_Helper_Form_Element_Select('parent', $options, $this->request->parent, _t('父级分类'),
|
||||
_t('此分类将归档在您选择的父级分类下.'));
|
||||
$parent = new Form\Element\Select(
|
||||
'parent',
|
||||
$options,
|
||||
$this->request->parent,
|
||||
_t('父级分类'),
|
||||
_t('此分类将归档在您选择的父级分类下.')
|
||||
);
|
||||
$form->addInput($parent);
|
||||
|
||||
/** 分类描述 */
|
||||
$description = new Typecho_Widget_Helper_Form_Element_Textarea('description', null, null,
|
||||
_t('分类描述'), _t('此文字用于描述分类, 在有的主题中它会被显示.'));
|
||||
$description = new Form\Element\Textarea(
|
||||
'description',
|
||||
null,
|
||||
null,
|
||||
_t('分类描述'),
|
||||
_t('此文字用于描述分类, 在有的主题中它会被显示.')
|
||||
);
|
||||
$form->addInput($description);
|
||||
|
||||
/** 分类动作 */
|
||||
$do = new Typecho_Widget_Helper_Form_Element_Hidden('do');
|
||||
$do = new Form\Element\Hidden('do');
|
||||
$form->addInput($do);
|
||||
|
||||
/** 分类主键 */
|
||||
$mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid');
|
||||
$mid = new Form\Element\Hidden('mid');
|
||||
$form->addInput($mid);
|
||||
|
||||
/** 提交按钮 */
|
||||
$submit = new Typecho_Widget_Helper_Form_Element_Submit();
|
||||
$submit = new Form\Element\Submit();
|
||||
$submit->input->setAttribute('class', 'btn primary');
|
||||
$form->addItem($submit);
|
||||
|
||||
@@ -209,7 +226,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
->where('type = ?', 'category')->limit(1));
|
||||
|
||||
if (!$meta) {
|
||||
$this->response->redirect(Typecho_Common::url('manage-categories.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-categories.php', $this->options->adminUrl));
|
||||
}
|
||||
|
||||
$name->value($meta['name']);
|
||||
@@ -251,8 +268,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
/**
|
||||
* 更新分类
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateCategory()
|
||||
{
|
||||
@@ -263,7 +279,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
/** 取出数据 */
|
||||
$category = $this->request->from('name', 'slug', 'description', 'parent');
|
||||
$category['mid'] = $this->request->mid;
|
||||
$category['slug'] = Typecho_Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
|
||||
$category['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
|
||||
$category['type'] = 'category';
|
||||
$current = $this->db->fetchRow($this->select()->where('mid = ?', $category['mid']));
|
||||
|
||||
@@ -286,14 +302,14 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
$this->push($category);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->theId);
|
||||
self::widget(Notice::class)->highlight($this->theId);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('分类 <a href="%s">%s</a> 已经被更新',
|
||||
$this->permalink, $this->name), 'success');
|
||||
self::widget(Notice::class)
|
||||
->set(_t('分类 <a href="%s">%s</a> 已经被更新', $this->permalink, $this->name), 'success');
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-categories.php'
|
||||
$this->response->redirect(Common::url('manage-categories.php'
|
||||
. ($category['parent'] ? '?parent=' . $category['parent'] : ''), $this->options->adminUrl));
|
||||
}
|
||||
|
||||
@@ -302,6 +318,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteCategory()
|
||||
{
|
||||
@@ -314,13 +331,13 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
if ($this->delete($this->db->sql()->where('mid = ?', $category))) {
|
||||
$this->db->query($this->db->delete('table.relationships')->where('mid = ?', $category));
|
||||
$this->update(['parent' => $parent], $this->db->sql()->where('parent = ?', $category));
|
||||
$deleteCount ++;
|
||||
$deleteCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('分类已经删除') : _t('没有分类被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)
|
||||
->set($deleteCount > 0 ? _t('分类已经删除') : _t('没有分类被删除'), $deleteCount > 0 ? 'success' : 'notice');
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->goBack();
|
||||
@@ -328,19 +345,16 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
|
||||
/**
|
||||
* 合并分类
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function mergeCategory()
|
||||
{
|
||||
/** 验证数据 */
|
||||
$validator = new Typecho_Validate();
|
||||
$validator = new Validate();
|
||||
$validator->addRule('merge', 'required', _t('分类主键不存在'));
|
||||
$validator->addRule('merge', [$this, 'categoryExists'], _t('请选择需要合并的分类'));
|
||||
|
||||
if ($error = $validator->run($this->request->from('merge'))) {
|
||||
$this->widget('Widget_Notice')->set($error, 'error');
|
||||
self::widget(Notice::class)->set($error, 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -351,9 +365,9 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
$this->merge($merge, 'category', $categories);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('分类已经合并'), 'success');
|
||||
self::widget(Notice::class)->set(_t('分类已经合并'), 'success');
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t('没有选择任何分类'), 'notice');
|
||||
self::widget(Notice::class)->set(_t('没有选择任何分类'), 'notice');
|
||||
}
|
||||
|
||||
/** 转向原页 */
|
||||
@@ -362,9 +376,6 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
|
||||
/**
|
||||
* 分类排序
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function sortCategory()
|
||||
{
|
||||
@@ -375,7 +386,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
|
||||
if (!$this->request->isAjax()) {
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-categories.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-categories.php', $this->options->adminUrl));
|
||||
} else {
|
||||
$this->response->throwJson(['success' => 1, 'message' => _t('分类排序已经完成')]);
|
||||
}
|
||||
@@ -384,8 +395,7 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
/**
|
||||
* 刷新分类
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function refreshCategory()
|
||||
{
|
||||
@@ -395,9 +405,9 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
$this->refreshCountByTypeAndStatus($category, 'post', 'publish');
|
||||
}
|
||||
|
||||
$this->widget('Widget_Notice')->set(_t('分类刷新已经完成'), 'success');
|
||||
self::widget(Notice::class)->set(_t('分类刷新已经完成'), 'success');
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t('没有选择任何分类'), 'notice');
|
||||
self::widget(Notice::class)->set(_t('没有选择任何分类'), 'notice');
|
||||
}
|
||||
|
||||
/** 转向原页 */
|
||||
@@ -407,20 +417,18 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
/**
|
||||
* 设置默认分类
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function defaultCategory()
|
||||
{
|
||||
/** 验证数据 */
|
||||
$validator = new Typecho_Validate();
|
||||
$validator = new Validate();
|
||||
$validator->addRule('mid', 'required', _t('分类主键不存在'));
|
||||
$validator->addRule('mid', [$this, 'categoryExists'], _t('分类不存在'));
|
||||
|
||||
if ($error = $validator->run($this->request->from('mid'))) {
|
||||
$this->widget('Widget_Notice')->set($error, 'error');
|
||||
self::widget(Notice::class)->set($error, 'error');
|
||||
} else {
|
||||
|
||||
$this->db->query($this->db->update('table.options')
|
||||
->rows(['value' => $this->request->mid])
|
||||
->where('name = ?', 'defaultCategory'));
|
||||
@@ -429,24 +437,26 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
->where('type = ?', 'category')->limit(1), [$this, 'push']);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->theId);
|
||||
self::widget(Notice::class)->highlight($this->theId);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('<a href="%s">%s</a> 已经被设为默认分类',
|
||||
$this->permalink, $this->name), 'success');
|
||||
self::widget(Notice::class)->set(
|
||||
_t('<a href="%s">%s</a> 已经被设为默认分类', $this->permalink, $this->name),
|
||||
'success'
|
||||
);
|
||||
}
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-categories.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-categories.php', $this->options->adminUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单标题
|
||||
*
|
||||
* @return string
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @return string|null
|
||||
* @throws \Typecho\Widget\Exception|Exception
|
||||
*/
|
||||
public function getMenuTitle()
|
||||
public function getMenuTitle(): ?string
|
||||
{
|
||||
if (isset($this->request->mid)) {
|
||||
$category = $this->db->fetchRow($this->select()
|
||||
@@ -466,10 +476,10 @@ class Widget_Metas_Category_Edit extends Widget_Abstract_Metas implements Widget
|
||||
}
|
||||
|
||||
} else {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new Typecho_Widget_Exception(_t('分类不存在'), 404);
|
||||
throw new \Typecho\Widget\Exception(_t('分类不存在'), 404);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -375,7 +375,7 @@ class Rows extends Metas
|
||||
*/
|
||||
public function getCategory(int $mid)
|
||||
{
|
||||
return isset($this->map[$mid]) ? $this->map[$mid] : null;
|
||||
return $this->map[$mid] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 标签云
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Metas\Tag;
|
||||
|
||||
use Typecho\Db;
|
||||
use Typecho\Widget\Exception;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签云组件
|
||||
@@ -18,27 +17,26 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Metas_Tag_Admin extends Widget_Metas_Tag_Cloud
|
||||
class Admin extends Cloud
|
||||
{
|
||||
/**
|
||||
* 入口函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$select = $this->select()->where('type = ?', 'tag')->order('mid', Typecho_Db::SORT_DESC);
|
||||
$select = $this->select()->where('type = ?', 'tag')->order('mid', Db::SORT_DESC);
|
||||
$this->db->fetchAll($select, [$this, 'push']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单标题
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @return string|null
|
||||
* @throws Exception|Db\Exception
|
||||
*/
|
||||
public function getMenuTitle()
|
||||
public function getMenuTitle(): ?string
|
||||
{
|
||||
if (isset($this->request->mid)) {
|
||||
$tag = $this->db->fetchRow($this->select()
|
||||
@@ -48,9 +46,9 @@ class Widget_Metas_Tag_Admin extends Widget_Metas_Tag_Cloud
|
||||
return _t('编辑标签 %s', $tag['name']);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new Typecho_Widget_Exception(_t('标签不存在'), 404);
|
||||
throw new Exception(_t('标签不存在'), 404);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 标签云
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Metas\Tag;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Db;
|
||||
use Widget\Base\Metas;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签云组件
|
||||
@@ -18,19 +18,18 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Metas_Tag_Cloud extends Widget_Abstract_Metas
|
||||
class Cloud extends Metas
|
||||
{
|
||||
/**
|
||||
* 入口函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Db\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->parameter->setDefault(['sort' => 'count', 'ignoreZeroCount' => false, 'desc' => true, 'limit' => 0]);
|
||||
$select = $this->select()->where('type = ?', 'tag')->order($this->parameter->sort,
|
||||
$this->parameter->desc ? Typecho_Db::SORT_DESC : Typecho_Db::SORT_ASC);
|
||||
$select = $this->select()->where('type = ?', 'tag')
|
||||
->order($this->parameter->sort, $this->parameter->desc ? Db::SORT_DESC : Db::SORT_ASC);
|
||||
|
||||
/** 忽略零数量 */
|
||||
if ($this->parameter->ignoreZeroCount) {
|
||||
@@ -48,11 +47,11 @@ class Widget_Metas_Tag_Cloud extends Widget_Abstract_Metas
|
||||
/**
|
||||
* 按分割数输出字符串
|
||||
*
|
||||
* @param ...$args 需要输出的值
|
||||
* @param mixed ...$args 需要输出的值
|
||||
*/
|
||||
public function split(...$args)
|
||||
{
|
||||
array_unshift($args, $this->count);
|
||||
echo call_user_func_array(['Typecho_Common', 'splitByCount'], $args);
|
||||
echo call_user_func_array([Common::class, 'splitByCount'], $args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 标签编辑
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\Metas\Tag;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Db\Exception;
|
||||
use Typecho\Widget\Helper\Form;
|
||||
use Widget\Base\Metas;
|
||||
use Widget\DoInterface;
|
||||
use Widget\Notice;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签编辑组件
|
||||
@@ -19,13 +22,10 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Interface_Do
|
||||
class Edit extends Metas implements DoInterface
|
||||
{
|
||||
/**
|
||||
* 入口函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -36,28 +36,28 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
/**
|
||||
* 判断标签是否存在
|
||||
*
|
||||
* @access public
|
||||
* @param integer $mid 标签主键
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function tagExists($mid)
|
||||
public function tagExists(int $mid): bool
|
||||
{
|
||||
$tag = $this->db->fetchRow($this->db->select()
|
||||
->from('table.metas')
|
||||
->where('type = ?', 'tag')
|
||||
->where('mid = ?', $mid)->limit(1));
|
||||
|
||||
return $tag ? true : false;
|
||||
return (bool)$tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断标签名称是否存在
|
||||
*
|
||||
* @access public
|
||||
* @param string $name 标签名称
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function nameExists($name)
|
||||
public function nameExists(string $name): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.metas')
|
||||
@@ -70,20 +70,19 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
}
|
||||
|
||||
$tag = $this->db->fetchRow($select);
|
||||
return $tag ? false : true;
|
||||
return !$tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断标签名转换到缩略名后是否合法
|
||||
*
|
||||
* @access public
|
||||
* @param string $name 标签名
|
||||
* @return boolean
|
||||
*/
|
||||
public function nameToSlug($name)
|
||||
public function nameToSlug(string $name): bool
|
||||
{
|
||||
if (empty($this->request->slug)) {
|
||||
$slug = Typecho_Common::slugName($name);
|
||||
$slug = Common::slugName($name);
|
||||
if (empty($slug) || !$this->slugExists($name)) {
|
||||
return false;
|
||||
}
|
||||
@@ -95,16 +94,16 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
/**
|
||||
* 判断标签缩略名是否存在
|
||||
*
|
||||
* @access public
|
||||
* @param string $slug 缩略名
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function slugExists($slug)
|
||||
public function slugExists(string $slug): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.metas')
|
||||
->where('type = ?', 'tag')
|
||||
->where('slug = ?', Typecho_Common::slugName($slug))
|
||||
->where('slug = ?', Common::slugName($slug))
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->mid) {
|
||||
@@ -112,14 +111,13 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
}
|
||||
|
||||
$tag = $this->db->fetchRow($select);
|
||||
return $tag ? false : true;
|
||||
return !$tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入标签
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function insertTag()
|
||||
{
|
||||
@@ -130,56 +128,67 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
/** 取出数据 */
|
||||
$tag = $this->request->from('name', 'slug');
|
||||
$tag['type'] = 'tag';
|
||||
$tag['slug'] = Typecho_Common::slugName(empty($tag['slug']) ? $tag['name'] : $tag['slug']);
|
||||
$tag['slug'] = Common::slugName(empty($tag['slug']) ? $tag['name'] : $tag['slug']);
|
||||
|
||||
/** 插入数据 */
|
||||
$tag['mid'] = $this->insert($tag);
|
||||
$this->push($tag);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->theId);
|
||||
self::widget(Notice::class)->highlight($this->theId);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('标签 <a href="%s">%s</a> 已经被增加',
|
||||
$this->permalink, $this->name), 'success');
|
||||
self::widget(Notice::class)->set(
|
||||
_t('标签 <a href="%s">%s</a> 已经被增加', $this->permalink, $this->name),
|
||||
'success'
|
||||
);
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成表单
|
||||
*
|
||||
* @access public
|
||||
* @param string $action 表单动作
|
||||
* @return Typecho_Widget_Helper_Form
|
||||
* @param string|null $action 表单动作
|
||||
* @return Form
|
||||
* @throws Exception
|
||||
*/
|
||||
public function form($action = null)
|
||||
public function form(?string $action = null): Form
|
||||
{
|
||||
/** 构建表格 */
|
||||
$form = new Typecho_Widget_Helper_Form($this->security->getIndex('/action/metas-tag-edit'),
|
||||
Typecho_Widget_Helper_Form::POST_METHOD);
|
||||
$form = new Form($this->security->getIndex('/action/metas-tag-edit'), Form::POST_METHOD);
|
||||
|
||||
/** 标签名称 */
|
||||
$name = new Typecho_Widget_Helper_Form_Element_Text('name', null, null,
|
||||
_t('标签名称') . ' *', _t('这是标签在站点中显示的名称.可以使用中文,如 "地球".'));
|
||||
$name = new Form\Element\Text(
|
||||
'name',
|
||||
null,
|
||||
null,
|
||||
_t('标签名称') . ' *',
|
||||
_t('这是标签在站点中显示的名称.可以使用中文,如 "地球".')
|
||||
);
|
||||
$form->addInput($name);
|
||||
|
||||
/** 标签缩略名 */
|
||||
$slug = new Typecho_Widget_Helper_Form_Element_Text('slug', null, null,
|
||||
_t('标签缩略名'), _t('标签缩略名用于创建友好的链接形式, 如果留空则默认使用标签名称.'));
|
||||
$slug = new Form\Element\Text(
|
||||
'slug',
|
||||
null,
|
||||
null,
|
||||
_t('标签缩略名'),
|
||||
_t('标签缩略名用于创建友好的链接形式, 如果留空则默认使用标签名称.')
|
||||
);
|
||||
$form->addInput($slug);
|
||||
|
||||
/** 标签动作 */
|
||||
$do = new Typecho_Widget_Helper_Form_Element_Hidden('do');
|
||||
$do = new Form\Element\Hidden('do');
|
||||
$form->addInput($do);
|
||||
|
||||
/** 标签主键 */
|
||||
$mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid');
|
||||
$mid = new Form\Element\Hidden('mid');
|
||||
$form->addInput($mid);
|
||||
|
||||
/** 提交按钮 */
|
||||
$submit = new Typecho_Widget_Helper_Form_Element_Submit();
|
||||
$submit = new Form\Element\Submit();
|
||||
$submit->input->setAttribute('class', 'btn primary');
|
||||
$form->addItem($submit);
|
||||
|
||||
@@ -190,7 +199,7 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
->where('type = ?', 'tag')->limit(1));
|
||||
|
||||
if (!$meta) {
|
||||
$this->response->redirect(Typecho_Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
}
|
||||
|
||||
$name->value($meta['name']);
|
||||
@@ -230,8 +239,7 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
/**
|
||||
* 更新标签
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateTag()
|
||||
{
|
||||
@@ -242,28 +250,29 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
/** 取出数据 */
|
||||
$tag = $this->request->from('name', 'slug', 'mid');
|
||||
$tag['type'] = 'tag';
|
||||
$tag['slug'] = Typecho_Common::slugName(empty($tag['slug']) ? $tag['name'] : $tag['slug']);
|
||||
$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->push($tag);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight($this->theId);
|
||||
self::widget(Notice::class)->highlight($this->theId);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('标签 <a href="%s">%s</a> 已经被更新',
|
||||
$this->permalink, $this->name), 'success');
|
||||
self::widget(Notice::class)->set(
|
||||
_t('标签 <a href="%s">%s</a> 已经被更新', $this->permalink, $this->name),
|
||||
'success'
|
||||
);
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除标签
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteTag()
|
||||
{
|
||||
@@ -274,35 +283,36 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
foreach ($tags as $tag) {
|
||||
if ($this->delete($this->db->sql()->where('mid = ?', $tag))) {
|
||||
$this->db->query($this->db->delete('table.relationships')->where('mid = ?', $tag));
|
||||
$deleteCount ++;
|
||||
$deleteCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('标签已经删除') : _t('没有标签被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
self::widget(Notice::class)->set(
|
||||
$deleteCount > 0 ? _t('标签已经删除') : _t('没有标签被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice'
|
||||
);
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并标签
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function mergeTag()
|
||||
{
|
||||
if (empty($this->request->merge)) {
|
||||
$this->widget('Widget_Notice')->set(_t('请填写需要合并到的标签'), 'notice');
|
||||
self::widget(Notice::class)->set(_t('请填写需要合并到的标签'), 'notice');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
$merge = $this->scanTags($this->request->merge);
|
||||
if (empty($merge)) {
|
||||
$this->widget('Widget_Notice')->set(_t('合并到的标签名不合法'), 'error');
|
||||
self::widget(Notice::class)->set(_t('合并到的标签名不合法'), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -312,13 +322,13 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
$this->merge($merge, 'tag', $tags);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('标签已经合并'), 'success');
|
||||
self::widget(Notice::class)->set(_t('标签已经合并'), 'success');
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t('没有选择任何标签'), 'notice');
|
||||
self::widget(Notice::class)->set(_t('没有选择任何标签'), 'notice');
|
||||
}
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
$this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,6 +336,7 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function refreshTag()
|
||||
{
|
||||
@@ -338,9 +349,9 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
// 自动清理标签
|
||||
$this->clearTags();
|
||||
|
||||
$this->widget('Widget_Notice')->set(_t('标签刷新已经完成'), 'success');
|
||||
self::widget(Notice::class)->set(_t('标签刷新已经完成'), 'success');
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t('没有选择任何标签'), 'notice');
|
||||
self::widget(Notice::class)->set(_t('没有选择任何标签'), 'notice');
|
||||
}
|
||||
|
||||
/** 转向原页 */
|
||||
@@ -352,6 +363,7 @@ class Widget_Metas_Tag_Edit extends Widget_Abstract_Metas implements Widget_Inte
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function action()
|
||||
{
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* Typecho Blog Platform
|
||||
*
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id: Widget.php 48 2008-03-16 02:51:40Z magike.net $
|
||||
*/
|
||||
|
||||
namespace Widget;
|
||||
|
||||
use Typecho\Cookie;
|
||||
use Typecho\Widget;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示框组件
|
||||
*
|
||||
* @package Widget
|
||||
*/
|
||||
class Widget_Notice extends Typecho_Widget
|
||||
class Notice extends Widget
|
||||
{
|
||||
/**
|
||||
* 提示高亮
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $highlight;
|
||||
@@ -26,24 +26,24 @@ class Widget_Notice extends Typecho_Widget
|
||||
/**
|
||||
* 高亮相关元素
|
||||
*
|
||||
* @access public
|
||||
* @param string $theId 需要高亮元素的id
|
||||
* @return void
|
||||
*/
|
||||
public function highlight($theId)
|
||||
public function highlight(string $theId)
|
||||
{
|
||||
$this->highlight = $theId;
|
||||
Typecho_Cookie::set('__typecho_notice_highlight', $theId,
|
||||
$this->widget('Widget_Options')->time + $this->widget('Widget_Options')->timezone + 86400);
|
||||
Cookie::set(
|
||||
'__typecho_notice_highlight',
|
||||
$theId,
|
||||
self::widget(Options::class)->time + self::widget(Options::class)->timezone + 86400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取高亮的id
|
||||
*
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
public function getHighlightId()
|
||||
public function getHighlightId(): int
|
||||
{
|
||||
return preg_match("/[0-9]+/", $this->highlight, $matches) ? $matches[0] : 0;
|
||||
}
|
||||
@@ -51,21 +51,26 @@ class Widget_Notice extends Typecho_Widget
|
||||
/**
|
||||
* 设定堆栈每一行的值
|
||||
*
|
||||
* @param string $value 值对应的键值
|
||||
* @param string|array $value 值对应的键值
|
||||
* @param string $type 提示类型
|
||||
* @param string $typeFix 兼容老插件
|
||||
* @return array
|
||||
*/
|
||||
public function set($value, $type = 'notice', $typeFix = 'notice')
|
||||
public function set($value, string $type = 'notice', string $typeFix = 'notice')
|
||||
{
|
||||
$notice = is_array($value) ? array_values($value) : [$value];
|
||||
if (empty($type) && $typeFix) {
|
||||
$type = $typeFix;
|
||||
}
|
||||
|
||||
Typecho_Cookie::set('__typecho_notice', json_encode($notice),
|
||||
$this->widget('Widget_Options')->time + $this->widget('Widget_Options')->timezone + 86400);
|
||||
Typecho_Cookie::set('__typecho_notice_type', $type,
|
||||
$this->widget('Widget_Options')->time + $this->widget('Widget_Options')->timezone + 86400);
|
||||
Cookie::set(
|
||||
'__typecho_notice',
|
||||
json_encode($notice),
|
||||
self::widget(Options::class)->time + self::widget(Options::class)->timezone + 86400
|
||||
);
|
||||
Cookie::set(
|
||||
'__typecho_notice_type',
|
||||
$type,
|
||||
self::widget(Options::class)->time + self::widget(Options::class)->timezone + 86400
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 全局选项
|
||||
*
|
||||
* @link typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Config;
|
||||
use Typecho\Db;
|
||||
use Typecho\Router;
|
||||
use Typecho\Router\Parser;
|
||||
use Typecho\Widget;
|
||||
use Typecho\Plugin\Exception as PluginException;
|
||||
use Typecho\Db\Exception as DbException;
|
||||
use Typecho\Date;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局选项组件
|
||||
@@ -18,13 +24,13 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Options extends Typecho_Widget
|
||||
class Options extends Widget
|
||||
{
|
||||
/**
|
||||
* 数据库对象
|
||||
*
|
||||
* @access protected
|
||||
* @var Typecho_Db
|
||||
* @var Db
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
@@ -34,7 +40,7 @@ class Widget_Options extends Typecho_Widget
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_pluginConfig = [];
|
||||
private $pluginConfig = [];
|
||||
|
||||
/**
|
||||
* 缓存的个人插件配置
|
||||
@@ -42,16 +48,15 @@ class Widget_Options extends Typecho_Widget
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_personalPluginConfig = [];
|
||||
private $personalPluginConfig = [];
|
||||
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @throws DbException
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
{
|
||||
@@ -62,15 +67,14 @@ class Widget_Options extends Typecho_Widget
|
||||
$this->row = $params;
|
||||
} else {
|
||||
/** 初始化数据库 */
|
||||
$this->db = Typecho_Db::get();
|
||||
$this->db = Db::get();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
@@ -114,7 +118,7 @@ class Widget_Options extends Typecho_Widget
|
||||
}
|
||||
|
||||
$this->originalSiteUrl = $this->siteUrl;
|
||||
$this->siteUrl = Typecho_Common::url(null, $this->siteUrl);
|
||||
$this->siteUrl = Common::url(null, $this->siteUrl);
|
||||
$this->plugins = unserialize($this->plugins);
|
||||
|
||||
/** 动态判断皮肤目录 */
|
||||
@@ -129,7 +133,7 @@ class Widget_Options extends Typecho_Widget
|
||||
$this->routingTable = unserialize($this->routingTable);
|
||||
if (!empty($this->db) && !isset($this->routingTable[0])) {
|
||||
/** 解析路由并缓存 */
|
||||
$parser = new Typecho_Router_Parser($this->routingTable);
|
||||
$parser = new Parser($this->routingTable);
|
||||
$parsedRoutingTable = $parser->parse();
|
||||
$this->routingTable = array_merge([$parsedRoutingTable], $this->routingTable);
|
||||
$this->db->query($this->db->update('table.options')->rows(['value' => serialize($this->routingTable)])
|
||||
@@ -142,10 +146,9 @@ class Widget_Options extends Typecho_Widget
|
||||
*
|
||||
* @param string $theme
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function themeFile($theme, $file = '')
|
||||
public function themeFile(string $theme, string $file = ''): string
|
||||
{
|
||||
return __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . trim($theme, './') . '/' . trim($file, './');
|
||||
}
|
||||
@@ -153,13 +156,10 @@ class Widget_Options extends Typecho_Widget
|
||||
/**
|
||||
* 重载父类push函数,将所有变量值压入堆栈
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array $value 每行的值
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function push(array $value)
|
||||
public function push(array $value): array
|
||||
{
|
||||
//将行数据按顺序置位
|
||||
$this->row[$value['name']] = $value['value'];
|
||||
@@ -169,92 +169,73 @@ class Widget_Options extends Typecho_Widget
|
||||
/**
|
||||
* 输出网站路径
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $path 子路径
|
||||
*
|
||||
* @return void
|
||||
* @param string|null $path 子路径
|
||||
*/
|
||||
public function siteUrl($path = null)
|
||||
public function siteUrl(?string $path = null)
|
||||
{
|
||||
echo Typecho_Common::url($path, $this->siteUrl);
|
||||
echo Common::url($path, $this->siteUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出解析地址
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $path 子路径
|
||||
*
|
||||
* @return void
|
||||
* @param string|null $path 子路径
|
||||
*/
|
||||
public function index($path = null)
|
||||
public function index(?string $path = null)
|
||||
{
|
||||
echo Typecho_Common::url($path, $this->index);
|
||||
echo Common::url($path, $this->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出模板路径
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $path 子路径
|
||||
* @param string $theme 模版名称
|
||||
*
|
||||
* @param string|null $path 子路径
|
||||
* @param string|null $theme 模版名称
|
||||
* @return string
|
||||
*/
|
||||
public function themeUrl($path = null, $theme = null)
|
||||
public function themeUrl(?string $path = null, ?string $theme = null): string
|
||||
{
|
||||
if (empty($theme)) {
|
||||
echo Typecho_Common::url($path, $this->themeUrl);
|
||||
echo Common::url($path, $this->themeUrl);
|
||||
}
|
||||
|
||||
$url = defined('__TYPECHO_THEME_URL__') ? __TYPECHO_THEME_URL__ :
|
||||
Typecho_Common::url(__TYPECHO_THEME_DIR__ . '/' . $theme, $this->siteUrl);
|
||||
Common::url(__TYPECHO_THEME_DIR__ . '/' . $theme, $this->siteUrl);
|
||||
|
||||
return Typecho_Common::url($path, $url);
|
||||
return Common::url($path, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出插件路径
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $path 子路径
|
||||
*
|
||||
* @return void
|
||||
* @param string|null $path 子路径
|
||||
*/
|
||||
public function pluginUrl($path = null)
|
||||
public function pluginUrl(?string $path = null)
|
||||
{
|
||||
echo Typecho_Common::url($path, $this->pluginUrl);
|
||||
echo Common::url($path, $this->pluginUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件目录
|
||||
*
|
||||
* @param $plugin
|
||||
*
|
||||
* @param string|null $plugin
|
||||
* @return string
|
||||
*/
|
||||
public function pluginDir($plugin = null)
|
||||
public function pluginDir(?string $plugin = null): string
|
||||
{
|
||||
return __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__;
|
||||
return Common::url($plugin, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出后台路径
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|null $path 子路径
|
||||
* @param bool $return
|
||||
*
|
||||
* @return void|string
|
||||
*/
|
||||
public function adminUrl(?string $path = null, bool $return = false)
|
||||
{
|
||||
$url = Typecho_Common::url($path, $this->adminUrl);
|
||||
$url = Common::url($path, $this->adminUrl);
|
||||
|
||||
if ($return) {
|
||||
return $url;
|
||||
@@ -269,18 +250,17 @@ class Widget_Options extends Typecho_Widget
|
||||
* @param string $type
|
||||
* @param string|null $file
|
||||
* @param bool $return
|
||||
*
|
||||
* @return void|string
|
||||
*/
|
||||
public function adminStaticUrl(string $type, ?string $file = null, bool $return = false)
|
||||
{
|
||||
$url = Typecho_Common::url($type, $this->adminUrl);
|
||||
$url = Common::url($type, $this->adminUrl);
|
||||
|
||||
if (empty($file)) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$url = Typecho_Common::url($file, $url) . '?v=' . $this->version;
|
||||
$url = Common::url($file, $url) . '?v=' . $this->version;
|
||||
|
||||
if ($return) {
|
||||
return $url;
|
||||
@@ -291,9 +271,6 @@ class Widget_Options extends Typecho_Widget
|
||||
|
||||
/**
|
||||
* 编码输出允许出现在评论中的html标签
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function commentsHTMLTagAllowed()
|
||||
{
|
||||
@@ -304,22 +281,23 @@ class Widget_Options extends Typecho_Widget
|
||||
* 获取插件系统参数
|
||||
*
|
||||
* @param mixed $pluginName 插件名称
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Typecho_Plugin_Exception
|
||||
* @throws PluginException
|
||||
*/
|
||||
public function plugin($pluginName)
|
||||
{
|
||||
if (!isset($this->_pluginConfig[$pluginName])) {
|
||||
if (!empty($this->row['plugin:' . $pluginName])
|
||||
&& false !== ($options = unserialize($this->row['plugin:' . $pluginName]))) {
|
||||
$this->_pluginConfig[$pluginName] = new Typecho_Config($options);
|
||||
if (!isset($this->pluginConfig[$pluginName])) {
|
||||
if (
|
||||
!empty($this->row['plugin:' . $pluginName])
|
||||
&& false !== ($options = unserialize($this->row['plugin:' . $pluginName]))
|
||||
) {
|
||||
$this->pluginConfig[$pluginName] = new Config($options);
|
||||
} else {
|
||||
throw new Typecho_Plugin_Exception(_t('插件%s的配置信息没有找到', $pluginName), 500);
|
||||
throw new PluginException(_t('插件%s的配置信息没有找到', $pluginName), 500);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_pluginConfig[$pluginName];
|
||||
return $this->pluginConfig[$pluginName];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,226 +306,217 @@ class Widget_Options extends Typecho_Widget
|
||||
* @param mixed $pluginName 插件名称
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Typecho_Plugin_Exception
|
||||
* @throws PluginException
|
||||
*/
|
||||
public function personalPlugin($pluginName)
|
||||
{
|
||||
if (!isset($this->_personalPluginConfig[$pluginName])) {
|
||||
if (!empty($this->row['_plugin:' . $pluginName])
|
||||
&& false !== ($options = unserialize($this->row['_plugin:' . $pluginName]))) {
|
||||
$this->_personalPluginConfig[$pluginName] = new Typecho_Config($options);
|
||||
if (!isset($this->personalPluginConfig[$pluginName])) {
|
||||
if (
|
||||
!empty($this->row['_plugin:' . $pluginName])
|
||||
&& false !== ($options = unserialize($this->row['_plugin:' . $pluginName]))
|
||||
) {
|
||||
$this->personalPluginConfig[$pluginName] = new Config($options);
|
||||
} else {
|
||||
throw new Typecho_Plugin_Exception(_t('插件%s的配置信息没有找到', $pluginName), 500);
|
||||
throw new PluginException(_t('插件%s的配置信息没有找到', $pluginName), 500);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_personalPluginConfig[$pluginName];
|
||||
return $this->personalPluginConfig[$pluginName];
|
||||
}
|
||||
|
||||
/**
|
||||
* RSS2.0
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___feedUrl()
|
||||
protected function ___feedUrl(): string
|
||||
{
|
||||
return Typecho_Router::url('feed', ['feed' => '/'], $this->index);
|
||||
return Router::url('feed', ['feed' => '/'], $this->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* RSS1.0
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___feedRssUrl()
|
||||
protected function ___feedRssUrl(): string
|
||||
{
|
||||
return Typecho_Router::url('feed', ['feed' => '/rss/'], $this->index);
|
||||
return Router::url('feed', ['feed' => '/rss/'], $this->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* ATOM1.O
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___feedAtomUrl()
|
||||
protected function ___feedAtomUrl(): string
|
||||
{
|
||||
return Typecho_Router::url('feed', ['feed' => '/atom/'], $this->index);
|
||||
return Router::url('feed', ['feed' => '/atom/'], $this->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论RSS2.0聚合
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___commentsFeedUrl()
|
||||
protected function ___commentsFeedUrl(): string
|
||||
{
|
||||
return Typecho_Router::url('feed', ['feed' => '/comments/'], $this->index);
|
||||
return Router::url('feed', ['feed' => '/comments/'], $this->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论RSS1.0聚合
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___commentsFeedRssUrl()
|
||||
protected function ___commentsFeedRssUrl(): string
|
||||
{
|
||||
return Typecho_Router::url('feed', ['feed' => '/rss/comments/'], $this->index);
|
||||
return Router::url('feed', ['feed' => '/rss/comments/'], $this->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论ATOM1.0聚合
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___commentsFeedAtomUrl()
|
||||
protected function ___commentsFeedAtomUrl(): string
|
||||
{
|
||||
return Typecho_Router::url('feed', ['feed' => '/atom/comments/'], $this->index);
|
||||
return Router::url('feed', ['feed' => '/atom/comments/'], $this->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlrpc api地址
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___xmlRpcUrl()
|
||||
protected function ___xmlRpcUrl(): string
|
||||
{
|
||||
return Typecho_Router::url('do', ['action' => 'xmlrpc'], $this->index);
|
||||
return Router::url('do', ['action' => 'xmlrpc'], $this->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取解析路径前缀
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___index()
|
||||
protected function ___index(): string
|
||||
{
|
||||
return ($this->rewrite || (defined('__TYPECHO_REWRITE__') && __TYPECHO_REWRITE__))
|
||||
? $this->rootUrl : Typecho_Common::url('index.php', $this->rootUrl);
|
||||
? $this->rootUrl : Common::url('index.php', $this->rootUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板路径
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___themeUrl()
|
||||
protected function ___themeUrl(): string
|
||||
{
|
||||
return defined('__TYPECHO_THEME_URL__') ? __TYPECHO_THEME_URL__ :
|
||||
Typecho_Common::url(__TYPECHO_THEME_DIR__ . '/' . $this->theme, $this->siteUrl);
|
||||
Common::url(__TYPECHO_THEME_DIR__ . '/' . $this->theme, $this->siteUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件路径
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___pluginUrl()
|
||||
protected function ___pluginUrl(): string
|
||||
{
|
||||
return defined('__TYPECHO_PLUGIN_URL__') ? __TYPECHO_PLUGIN_URL__ :
|
||||
Typecho_Common::url(__TYPECHO_PLUGIN_DIR__, $this->siteUrl);
|
||||
Common::url(__TYPECHO_PLUGIN_DIR__, $this->siteUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后台路径
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___adminUrl()
|
||||
protected function ___adminUrl(): string
|
||||
{
|
||||
return Typecho_Common::url(defined('__TYPECHO_ADMIN_DIR__') ?
|
||||
return Common::url(defined('__TYPECHO_ADMIN_DIR__') ?
|
||||
__TYPECHO_ADMIN_DIR__ : '/admin/', $this->rootUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录地址
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___loginUrl()
|
||||
protected function ___loginUrl(): string
|
||||
{
|
||||
return Typecho_Common::url('login.php', $this->adminUrl);
|
||||
return Common::url('login.php', $this->adminUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录提交地址
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___loginAction()
|
||||
protected function ___loginAction(): string
|
||||
{
|
||||
return $this->widget('Widget_Security')->getTokenUrl(
|
||||
Typecho_Router::url('do', ['action' => 'login', 'widget' => 'Login'],
|
||||
Typecho_Common::url('index.php', $this->rootUrl)));
|
||||
return self::widget(Security::class)->getTokenUrl(
|
||||
Router::url(
|
||||
'do',
|
||||
['action' => 'login', 'widget' => 'Login'],
|
||||
Common::url('index.php', $this->rootUrl)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取注册地址
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___registerUrl()
|
||||
protected function ___registerUrl(): string
|
||||
{
|
||||
return Typecho_Common::url('register.php', $this->adminUrl);
|
||||
return Common::url('register.php', $this->adminUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录提交地址
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
* @throws Widget\Exception
|
||||
*/
|
||||
protected function ___registerAction()
|
||||
protected function ___registerAction(): string
|
||||
{
|
||||
return $this->widget('Widget_Security')->getTokenUrl(
|
||||
Typecho_Router::url('do', ['action' => 'register', 'widget' => 'Register'], $this->index));
|
||||
return self::widget(Security::class)->getTokenUrl(
|
||||
Router::url('do', ['action' => 'register', 'widget' => 'Register'], $this->index)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人档案地址
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___profileUrl()
|
||||
protected function ___profileUrl(): string
|
||||
{
|
||||
return Typecho_Common::url('profile.php', $this->adminUrl);
|
||||
return Common::url('profile.php', $this->adminUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登出地址
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___logoutUrl()
|
||||
protected function ___logoutUrl(): string
|
||||
{
|
||||
return $this->widget('Widget_Security')->getTokenUrl(
|
||||
Typecho_Common::url('/action/logout', $this->index));
|
||||
return self::widget(Security::class)->getTokenUrl(
|
||||
Common::url('/action/logout', $this->index)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统时区
|
||||
*
|
||||
* @access protected
|
||||
* @return integer
|
||||
*/
|
||||
protected function ___serverTimezone()
|
||||
protected function ___serverTimezone(): int
|
||||
{
|
||||
return Typecho_Date::$serverTimezoneOffset;
|
||||
return Date::$serverTimezoneOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -555,11 +524,10 @@ class Widget_Options extends Typecho_Widget
|
||||
*
|
||||
* @return integer
|
||||
* @deprecated
|
||||
* @access protected
|
||||
*/
|
||||
protected function ___gmtTime()
|
||||
protected function ___gmtTime(): int
|
||||
{
|
||||
return Typecho_Date::gmtTime();
|
||||
return Date::gmtTime();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -567,20 +535,18 @@ class Widget_Options extends Typecho_Widget
|
||||
*
|
||||
* @return integer
|
||||
* @deprecated
|
||||
* @access protected
|
||||
*/
|
||||
protected function ___time()
|
||||
protected function ___time(): int
|
||||
{
|
||||
return Typecho_Date::time();
|
||||
return Date::time();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取格式
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___contentType()
|
||||
protected function ___contentType(): string
|
||||
{
|
||||
return $this->contentType ?? 'text/html';
|
||||
}
|
||||
@@ -588,10 +554,9 @@ class Widget_Options extends Typecho_Widget
|
||||
/**
|
||||
* 软件名称
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___software()
|
||||
protected function ___software(): string
|
||||
{
|
||||
[$software, $version] = explode(' ', $this->generator);
|
||||
return $software;
|
||||
@@ -600,10 +565,9 @@ class Widget_Options extends Typecho_Widget
|
||||
/**
|
||||
* 软件版本
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function ___version()
|
||||
protected function ___version(): string
|
||||
{
|
||||
[$software, $version] = explode(' ', $this->generator);
|
||||
$pos = strpos($version, '/');
|
||||
@@ -619,10 +583,9 @@ class Widget_Options extends Typecho_Widget
|
||||
/**
|
||||
* 允许上传的文件类型
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
protected function ___allowedAttachmentTypes()
|
||||
protected function ___allowedAttachmentTypes(): array
|
||||
{
|
||||
$attachmentTypesResult = [];
|
||||
|
||||
@@ -632,7 +595,9 @@ class Widget_Options extends Typecho_Widget
|
||||
[
|
||||
'gif,jpg,jpeg,png,tiff,bmp', 'mp3,mp4,mov,wmv,wma,rmvb,rm,avi,flv,ogg,oga,ogv',
|
||||
'txt,doc,docx,xls,xlsx,ppt,pptx,zip,rar,pdf'
|
||||
], $this->attachmentTypes);
|
||||
],
|
||||
$this->attachmentTypes
|
||||
);
|
||||
|
||||
$attachmentTypesResult = array_unique(array_map('trim', preg_split("/(,|\.)/", $attachmentTypes)));
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class Widget_Options_Discussion extends Widget_Abstract_Options implements Widge
|
||||
$this->update(['value' => $value], $this->db->sql()->where('name = ?', $name));
|
||||
}
|
||||
|
||||
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ class Widget_Options_General extends Widget_Abstract_Options implements Widget_I
|
||||
$this->update(['value' => $value], $this->db->sql()->where('name = ?', $name));
|
||||
}
|
||||
|
||||
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
|
||||
@@ -174,9 +174,9 @@ RewriteRule . {$basePath}index.php [L]
|
||||
}
|
||||
|
||||
if ($patternValid) {
|
||||
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."), 'notice');
|
||||
self::widget('Widget_Notice')->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."), 'notice');
|
||||
}
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class Widget_Options_Reading extends Widget_Options_Permalink
|
||||
$this->update(['value' => $value], $this->db->sql()->where('name = ?', $name));
|
||||
}
|
||||
|
||||
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
|
||||
$this->db->sql()->where('name = ?', 'plugins'));
|
||||
} catch (Typecho_Plugin_Exception $e) {
|
||||
/** 截获异常 */
|
||||
$this->widget('Widget_Notice')->set($e->getMessage(), 'error');
|
||||
self::widget('Widget_Notice')->set($e->getMessage(), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -89,12 +89,12 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
|
||||
}
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight('plugin-' . $pluginName);
|
||||
self::widget('Widget_Notice')->highlight('plugin-' . $pluginName);
|
||||
|
||||
if (isset($result) && is_string($result)) {
|
||||
$this->widget('Widget_Notice')->set($result, 'notice');
|
||||
self::widget('Widget_Notice')->set($result, 'notice');
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t('插件已经被启用'), 'success');
|
||||
self::widget('Widget_Notice')->set(_t('插件已经被启用'), 'success');
|
||||
}
|
||||
$this->response->goBack();
|
||||
}
|
||||
@@ -117,7 +117,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
|
||||
$result = call_user_func([$className, 'configCheck'], $settings);
|
||||
|
||||
if (!empty($result) && is_string($result)) {
|
||||
$this->widget('Widget_Notice')->set($result, 'notice');
|
||||
self::widget('Widget_Notice')->set($result, 'notice');
|
||||
$this->_configNoticed = true;
|
||||
}
|
||||
}
|
||||
@@ -237,12 +237,12 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
|
||||
$result = call_user_func([$className, 'deactivate']);
|
||||
} catch (Typecho_Plugin_Exception $e) {
|
||||
/** 截获异常 */
|
||||
$this->widget('Widget_Notice')->set($e->getMessage(), 'error');
|
||||
self::widget('Widget_Notice')->set($e->getMessage(), 'error');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight('plugin-' . $pluginName);
|
||||
self::widget('Widget_Notice')->highlight('plugin-' . $pluginName);
|
||||
}
|
||||
|
||||
Typecho_Plugin::deactivate($pluginName);
|
||||
@@ -253,9 +253,9 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
|
||||
$this->delete($this->db->sql()->where('name = ?', '_plugin:' . $pluginName));
|
||||
|
||||
if (isset($result) && is_string($result)) {
|
||||
$this->widget('Widget_Notice')->set($result, 'notice');
|
||||
self::widget('Widget_Notice')->set($result, 'notice');
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t('插件已经被禁用'), 'success');
|
||||
self::widget('Widget_Notice')->set(_t('插件已经被禁用'), 'success');
|
||||
}
|
||||
$this->response->goBack();
|
||||
}
|
||||
@@ -269,7 +269,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
|
||||
*/
|
||||
public function config($pluginName)
|
||||
{
|
||||
$form = $this->widget('Widget_Plugins_Config')->config();
|
||||
$form = self::widget('Widget_Plugins_Config')->config();
|
||||
|
||||
/** 验证表单 */
|
||||
if ($form->validate()) {
|
||||
@@ -283,11 +283,11 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
|
||||
}
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight('plugin-' . $pluginName);
|
||||
self::widget('Widget_Notice')->highlight('plugin-' . $pluginName);
|
||||
|
||||
if (!$this->_configNoticed) {
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t("插件设置已经保存"), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("插件设置已经保存"), 'success');
|
||||
}
|
||||
|
||||
/** 转向原页 */
|
||||
|
||||
@@ -53,7 +53,7 @@ class Widget_Register extends Widget_Abstract_Users implements Widget_Interface_
|
||||
Typecho_Cookie::set('__typecho_remember_mail', $this->request->mail);
|
||||
|
||||
/** 设置提示信息 */
|
||||
$this->widget('Widget_Notice')->set($error);
|
||||
self::widget('Widget_Notice')->set($error);
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class Widget_Register extends Widget_Abstract_Users implements Widget_Interface_
|
||||
Typecho_Cookie::delete('__typecho_remember_name');
|
||||
Typecho_Cookie::delete('__typecho_remember_mail');
|
||||
|
||||
$this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $this->screenName, $generatedPassword), 'success');
|
||||
self::widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $this->screenName, $generatedPassword), 'success');
|
||||
$this->response->redirect($this->options->adminUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
|
||||
namespace Widget;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Widget;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全选项组件
|
||||
@@ -9,84 +17,51 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2014 Typecho team (http://typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Security extends Typecho_Widget
|
||||
class Security extends Widget
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_token;
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* @var Widget_Options
|
||||
* @var Options
|
||||
*/
|
||||
private $_options;
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $_enabled = true;
|
||||
private $enabled = true;
|
||||
|
||||
/**
|
||||
* 初始化函数
|
||||
*
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->_options = $this->widget('Widget_Options');
|
||||
$user = $this->widget('Widget_User');
|
||||
$this->options = self::widget(Options::class);
|
||||
$user = self::widget(User::class);
|
||||
|
||||
$this->_token = $this->_options->secret;
|
||||
$this->token = $this->options->secret;
|
||||
if ($user->hasLogin()) {
|
||||
$this->_token .= '&' . $user->authCode . '&' . $user->uid;
|
||||
$this->token .= '&' . $user->authCode . '&' . $user->uid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在系统升级的时候进行安全性检查
|
||||
*
|
||||
* @return array
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function systemCheck()
|
||||
public function enable(bool $enabled = true)
|
||||
{
|
||||
$errors = [];
|
||||
|
||||
// 检查安装文件的安全性
|
||||
$installFile = __TYPECHO_ROOT_DIR__ . '/install.php';
|
||||
if (file_exists($installFile)) {
|
||||
$installFileContents = file_get_contents($installFile);
|
||||
|
||||
if (0 !== strpos($installFileContents,
|
||||
'<?php if (!file_exists(dirname(__FILE__) . \'/config.inc.php\')): ?>') ||
|
||||
false !== strpos($installFileContents,
|
||||
'!isset($_GET[\'finish\']) && file_exists(__TYPECHO_ROOT_DIR__ . \'/config.inc.php\') && empty($_SESSION[\'typecho\'])')) {
|
||||
$errors[] = _t('您正在运行一个不安全的安装脚本 <strong>%s</strong>, 请用新版中的对应文件替代或者直接删除它', $installFile);
|
||||
}
|
||||
}
|
||||
|
||||
// 验证入口文件
|
||||
$indexFile = __TYPECHO_ROOT_DIR__ . '/index.php';
|
||||
if (md5_file($indexFile) != 'f4dae7ceb7002cf4f95d380f5ced906b') {
|
||||
$errors[] = _t('当前网站的入口文件 <strong>%s</strong> 与最新版中的不一致, 请更新', $indexFile);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $enabled
|
||||
*/
|
||||
public function enable($enabled = true)
|
||||
{
|
||||
$this->_enabled = $enabled;
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保护提交数据
|
||||
*
|
||||
*/
|
||||
public function protect()
|
||||
{
|
||||
if ($this->_enabled && $this->request->get('_') != $this->getToken($this->request->getReferer())) {
|
||||
if ($this->enabled && $this->request->get('_') != $this->getToken($this->request->getReferer())) {
|
||||
$this->response->goBack();
|
||||
}
|
||||
}
|
||||
@@ -97,9 +72,9 @@ class Widget_Security extends Typecho_Widget
|
||||
* @param string $suffix 后缀
|
||||
* @return string
|
||||
*/
|
||||
public function getToken($suffix)
|
||||
public function getToken(string $suffix): string
|
||||
{
|
||||
return md5($this->_token . '&' . $suffix);
|
||||
return md5($this->token . '&' . $suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,9 +83,9 @@ class Widget_Security extends Typecho_Widget
|
||||
* @param $path
|
||||
* @return string
|
||||
*/
|
||||
public function getRootUrl($path)
|
||||
public function getRootUrl($path): string
|
||||
{
|
||||
return Typecho_Common::url($this->getTokenUrl($path), $this->_options->rootUrl);
|
||||
return Common::url($this->getTokenUrl($path), $this->options->rootUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +95,7 @@ class Widget_Security extends Typecho_Widget
|
||||
* @param string|null $url
|
||||
* @return string
|
||||
*/
|
||||
public function getTokenUrl($path, ?string $url = null)
|
||||
public function getTokenUrl($path, ?string $url = null): string
|
||||
{
|
||||
$parts = parse_url($path);
|
||||
$params = [];
|
||||
@@ -132,7 +107,7 @@ class Widget_Security extends Typecho_Widget
|
||||
$params['_'] = $this->getToken($url ?: $this->request->getRequestUrl());
|
||||
$parts['query'] = http_build_query($params);
|
||||
|
||||
return Typecho_Common::buildUrl($parts);
|
||||
return Common::buildUrl($parts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,9 +126,9 @@ class Widget_Security extends Typecho_Widget
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function getAdminUrl($path)
|
||||
public function getAdminUrl(string $path): string
|
||||
{
|
||||
return Typecho_Common::url($this->getTokenUrl($path), $this->_options->adminUrl);
|
||||
return Common::url($this->getTokenUrl($path), $this->options->adminUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,9 +147,9 @@ class Widget_Security extends Typecho_Widget
|
||||
* @param $path
|
||||
* @return string
|
||||
*/
|
||||
public function getIndex($path)
|
||||
public function getIndex($path): string
|
||||
{
|
||||
return Typecho_Common::url($this->getTokenUrl($path), $this->_options->index);
|
||||
return Common::url($this->getTokenUrl($path), $this->options->index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 通用异步服务
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Http\Client;
|
||||
use Typecho\Plugin;
|
||||
use Typecho\Response;
|
||||
use Typecho\Widget\Exception;
|
||||
use Widget\Base\Options as BaseOptions;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用异步服务组件
|
||||
@@ -17,7 +20,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
*/
|
||||
class Widget_Service extends Widget_Abstract_Options implements Widget_Interface_Do
|
||||
class Service extends BaseOptions implements DoInterface
|
||||
{
|
||||
/**
|
||||
* 异步请求
|
||||
@@ -29,17 +32,15 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
/**
|
||||
* 发送pingback实现
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @throws Exception|Client\Exception
|
||||
*/
|
||||
public function sendPingHandle()
|
||||
{
|
||||
/** 验证权限 */
|
||||
$token = $this->request->token;
|
||||
|
||||
if (!Typecho_Common::timeTokenValidate($token, $this->options->secret, 3)) {
|
||||
throw new Typecho_Widget_Exception(_t('禁止访问'), 403);
|
||||
if (!Common::timeTokenValidate($token, $this->options->secret, 3)) {
|
||||
throw new Exception(_t('禁止访问'), 403);
|
||||
}
|
||||
|
||||
/** 忽略超时 */
|
||||
@@ -52,7 +53,7 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
}
|
||||
|
||||
/** 获取post */
|
||||
$post = $this->widget('Widget_Archive', "type=post", "cid={$this->request->cid}");
|
||||
$post = self::widget('Widget_Archive', "type=post", "cid={$this->request->cid}");
|
||||
|
||||
if ($post->have() && preg_match_all("|<a[^>]*href=[\"'](.*?)[\"'][^>]*>(.*?)</a>|", $post->text, $matches)) {
|
||||
$links = array_unique($matches[1]);
|
||||
@@ -68,29 +69,34 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
}
|
||||
} else {
|
||||
$urlPart['scheme'] = 'http';
|
||||
$url = Typecho_Common::buildUrl($urlPart);
|
||||
$url = Common::buildUrl($urlPart);
|
||||
}
|
||||
|
||||
if ($permalinkPart['host'] == $urlPart['host'] && $permalinkPart['path'] == $urlPart['path']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$spider = Typecho_Http_Client::get();
|
||||
$spider = Client::get();
|
||||
|
||||
if ($spider) {
|
||||
$spider->setTimeout(10)
|
||||
->send($url);
|
||||
|
||||
if (!($xmlrpcUrl = $spider->getResponseHeader('x-pingback'))) {
|
||||
if (preg_match("/<link[^>]*rel=[\"']pingback[\"'][^>]*href=[\"']([^\"']+)[\"'][^>]*>/i",
|
||||
$spider->getResponseBody(), $out)) {
|
||||
if (
|
||||
preg_match(
|
||||
"/<link[^>]*rel=[\"']pingback[\"'][^>]*href=[\"']([^\"']+)[\"'][^>]*>/i",
|
||||
$spider->getResponseBody(),
|
||||
$out
|
||||
)
|
||||
) {
|
||||
$xmlrpcUrl = $out[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($xmlrpcUrl)) {
|
||||
try {
|
||||
$xmlrpc = new IXR_Client($xmlrpcUrl);
|
||||
$xmlrpc = new \IXR\Client($xmlrpcUrl);
|
||||
$xmlrpc->pingback->ping($post->permalink, $url);
|
||||
unset($xmlrpc);
|
||||
} catch (Exception $e) {
|
||||
@@ -108,8 +114,7 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
$links = array_filter(array_map('trim', explode("\n", $this->request->trackback)));
|
||||
|
||||
foreach ($links as $url) {
|
||||
|
||||
$client = Typecho_Http_Client::get();
|
||||
$client = Client::get();
|
||||
|
||||
if ($client) {
|
||||
try {
|
||||
@@ -122,7 +127,7 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
->send($url);
|
||||
|
||||
unset($client);
|
||||
} catch (Typecho_Http_Client_Exception $e) {
|
||||
} catch (Client\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -137,22 +142,19 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
* $this->sendPingbacks(365);
|
||||
* </code>
|
||||
*
|
||||
* @access public
|
||||
* @param integer $cid 内容id
|
||||
* @param array $trackback trackback的url
|
||||
* @return void
|
||||
* @param array|null $trackback trackback的url
|
||||
*/
|
||||
public function sendPing($cid, array $trackback = null)
|
||||
public function sendPing($cid, ?array $trackback = null)
|
||||
{
|
||||
$this->user->pass('contributor');
|
||||
|
||||
if ($client = Typecho_Http_Client::get()) {
|
||||
if ($client = Client::get()) {
|
||||
try {
|
||||
|
||||
$input = [
|
||||
'do' => 'ping',
|
||||
'cid' => $cid,
|
||||
'token' => Typecho_Common::timeToken($this->options->secret)
|
||||
'token' => Common::timeToken($this->options->secret)
|
||||
];
|
||||
|
||||
if (!empty($trackback)) {
|
||||
@@ -162,10 +164,9 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
$client->setHeader('User-Agent', $this->options->generator)
|
||||
->setTimeout(2)
|
||||
->setData($input)
|
||||
->setMethod(Typecho_Http_Client::METHOD_POST)
|
||||
->setMethod(Client::METHOD_POST)
|
||||
->send($this->getServiceUrl());
|
||||
|
||||
} catch (Typecho_Http_Client_Exception $e) {
|
||||
} catch (Client\Exception $e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -176,23 +177,25 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getServiceUrl()
|
||||
private function getServiceUrl(): string
|
||||
{
|
||||
$url = Typecho_Common::url('/action/service', $this->options->index);
|
||||
$url = Common::url('/action/service', $this->options->index);
|
||||
|
||||
if (defined('__TYPECHO_SERVICE_URL__')) {
|
||||
$rootPath = rtrim(parse_url($this->options->rootUrl, PHP_URL_PATH), '/');
|
||||
$path = parse_url($url, PHP_URL_PATH);
|
||||
$parts = parse_url(__TYPECHO_SERVICE_URL__);
|
||||
|
||||
if (!empty($parts['path'])
|
||||
if (
|
||||
!empty($parts['path'])
|
||||
&& $parts['path'] != '/'
|
||||
&& rtrim($parts['path'], '/') != $rootPath) {
|
||||
$path = Typecho_Common::url($path, $parts['path']);
|
||||
&& rtrim($parts['path'], '/') != $rootPath
|
||||
) {
|
||||
$path = Common::url($path, $parts['path']);
|
||||
}
|
||||
|
||||
$parts['path'] = $path;
|
||||
$url = Typecho_Common::buildUrl($parts);
|
||||
$url = Common::buildUrl($parts);
|
||||
}
|
||||
|
||||
return $url;
|
||||
@@ -209,22 +212,19 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
static $called;
|
||||
|
||||
if (!$called) {
|
||||
$self = $this;
|
||||
|
||||
Typecho_Response::addCallback(function () use ($self) {
|
||||
if (!empty($self->asyncRequests) && $client = Typecho_Http_Client::get()) {
|
||||
Response::getInstance()->addResponder(function () {
|
||||
if (!empty($self->asyncRequests) && $client = Client::get()) {
|
||||
try {
|
||||
$client->setHeader('User-Agent', $this->options->generator)
|
||||
->setTimeout(2)
|
||||
->setData([
|
||||
'do' => 'async',
|
||||
'requests' => json_encode($self->asyncRequests),
|
||||
'token' => Typecho_Common::timeToken($this->options->secret)
|
||||
'token' => Common::timeToken($this->options->secret)
|
||||
])
|
||||
->setMethod(Typecho_Http_Client::METHOD_POST)
|
||||
->setMethod(Client::METHOD_POST)
|
||||
->send($this->getServiceUrl());
|
||||
|
||||
} catch (Typecho_Http_Client_Exception $e) {
|
||||
} catch (Client\Exception $e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -239,15 +239,15 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
/**
|
||||
* 执行回调
|
||||
*
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function asyncHandle()
|
||||
{
|
||||
/** 验证权限 */
|
||||
$token = $this->request->token;
|
||||
|
||||
if (!Typecho_Common::timeTokenValidate($token, $this->options->secret, 3)) {
|
||||
throw new Typecho_Widget_Exception(_t('禁止访问'), 403);
|
||||
if (!Common::timeTokenValidate($token, $this->options->secret, 3)) {
|
||||
throw new Exception(_t('禁止访问'), 403);
|
||||
}
|
||||
|
||||
/** 忽略超时 */
|
||||
@@ -260,7 +260,7 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
}
|
||||
|
||||
$requests = json_decode($this->request->requests, true);
|
||||
$plugin = Typecho_Plugin::factory(__CLASS__);
|
||||
$plugin = Plugin::factory(__CLASS__);
|
||||
|
||||
if (!empty($requests)) {
|
||||
foreach ($requests as $request) {
|
||||
@@ -272,9 +272,6 @@ class Widget_Service extends Widget_Abstract_Options implements Widget_Interface
|
||||
|
||||
/**
|
||||
* 异步请求入口
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function action()
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ class Widget_Stat extends Typecho_Widget
|
||||
$this->db = Typecho_Db::get();
|
||||
|
||||
/** 初始化常用组件 */
|
||||
$this->user = $this->widget('Widget_User');
|
||||
$this->user = self::widget('Widget_User');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,8 +63,8 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
|
||||
}
|
||||
}
|
||||
|
||||
$this->widget('Widget_Notice')->highlight('theme-' . $theme);
|
||||
$this->widget('Widget_Notice')->set(_t("外观已经改变"), 'success');
|
||||
self::widget('Widget_Notice')->highlight('theme-' . $theme);
|
||||
self::widget('Widget_Notice')->set(_t("外观已经改变"), 'success');
|
||||
$this->response->goBack();
|
||||
} else {
|
||||
throw new Typecho_Widget_Exception(_t('您选择的风格不存在'));
|
||||
@@ -107,9 +107,9 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
|
||||
$handle = fopen($path, 'wb');
|
||||
if ($handle && fwrite($handle, $this->request->content)) {
|
||||
fclose($handle);
|
||||
$this->widget('Widget_Notice')->set(_t("文件 %s 的更改已经保存", $file), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("文件 %s 的更改已经保存", $file), 'success');
|
||||
} else {
|
||||
$this->widget('Widget_Notice')->set(_t("文件 %s 无法被写入", $file), 'error');
|
||||
self::widget('Widget_Notice')->set(_t("文件 %s 无法被写入", $file), 'error');
|
||||
}
|
||||
$this->response->goBack();
|
||||
} else {
|
||||
@@ -127,7 +127,7 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
|
||||
public function config($theme)
|
||||
{
|
||||
// 已经载入了外观函数
|
||||
$form = $this->widget('Widget_Themes_Config')->config();
|
||||
$form = self::widget('Widget_Themes_Config')->config();
|
||||
|
||||
/** 验证表单 */
|
||||
if ($form->validate()) {
|
||||
@@ -150,10 +150,10 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
|
||||
}
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight('theme-' . $theme);
|
||||
self::widget('Widget_Notice')->highlight('theme-' . $theme);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t("外观设置已经保存"), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("外观设置已经保存"), 'success');
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('options-theme.php', $this->options->adminUrl));
|
||||
|
||||
@@ -47,11 +47,11 @@ class Widget_Themes_Files extends Typecho_Widget
|
||||
public function execute()
|
||||
{
|
||||
/** 管理员权限 */
|
||||
$this->widget('Widget_User')->pass('administrator');
|
||||
$this->_currentTheme = $this->request->filter('slug')->get('theme', $this->widget('Widget_Options')->theme);
|
||||
self::widget('Widget_User')->pass('administrator');
|
||||
$this->_currentTheme = $this->request->filter('slug')->get('theme', self::widget('Widget_Options')->theme);
|
||||
|
||||
if (preg_match("/^([_0-9a-z-\.\ ])+$/i", $this->_currentTheme)
|
||||
&& is_dir($dir = $this->widget('Widget_Options')->themeFile($this->_currentTheme))
|
||||
&& is_dir($dir = self::widget('Widget_Options')->themeFile($this->_currentTheme))
|
||||
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__)) {
|
||||
|
||||
$files = array_filter(glob($dir . '/*'), function ($path) {
|
||||
@@ -99,7 +99,7 @@ class Widget_Themes_Files extends Typecho_Widget
|
||||
*/
|
||||
public function currentContent()
|
||||
{
|
||||
return htmlspecialchars(file_get_contents($this->widget('Widget_Options')
|
||||
return htmlspecialchars(file_get_contents(self::widget('Widget_Options')
|
||||
->themeFile($this->_currentTheme, $this->_currentFile)));
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class Widget_Themes_Files extends Typecho_Widget
|
||||
*/
|
||||
public function currentIsWriteable()
|
||||
{
|
||||
return is_writeable($this->widget('Widget_Options')
|
||||
return is_writeable(self::widget('Widget_Options')
|
||||
->themeFile($this->_currentTheme, $this->_currentFile))
|
||||
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class Widget_Themes_List extends Typecho_Widget
|
||||
$themes = $this->getThemes();
|
||||
|
||||
if ($themes) {
|
||||
$options = $this->widget('Widget_Options');
|
||||
$options = self::widget('Widget_Options');
|
||||
$activated = 0;
|
||||
$result = [];
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
|
||||
$version .= '/' . $minor;
|
||||
}
|
||||
|
||||
$options = $this->widget('Widget_Options@' . $package);
|
||||
$options = self::widget('Widget_Options@' . $package);
|
||||
|
||||
/** 执行升级脚本 */
|
||||
try {
|
||||
@@ -68,7 +68,7 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
|
||||
$message[] = $result;
|
||||
}
|
||||
} catch (Typecho_Exception $e) {
|
||||
$this->widget('Widget_Notice')->set($e->getMessage(), 'error');
|
||||
self::widget('Widget_Notice')->set($e->getMessage(), 'error');
|
||||
$this->response->goBack();
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
|
||||
$this->update(['value' => 'Typecho ' . Typecho_Common::VERSION],
|
||||
$this->db->sql()->where('name = ?', 'generator'));
|
||||
|
||||
$this->widget('Widget_Notice')->set(empty($message) ? _t("升级已经完成") : $message,
|
||||
self::widget('Widget_Notice')->set(empty($message) ? _t("升级已经完成") : $message,
|
||||
empty($message) ? 'success' : 'notice');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 上传动作
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Date;
|
||||
use Typecho\Db\Exception;
|
||||
use Typecho\Plugin;
|
||||
use Typecho\Widget;
|
||||
use Widget\Base\Contents;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传组件
|
||||
@@ -17,21 +20,20 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
*/
|
||||
class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface_Do
|
||||
class Upload extends Contents implements DoInterface
|
||||
{
|
||||
//上传文件目录
|
||||
const UPLOAD_DIR = '/usr/uploads';
|
||||
public const UPLOAD_DIR = '/usr/uploads';
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @access public
|
||||
* @param array $content 文件相关信息
|
||||
* @return string
|
||||
* @return bool
|
||||
*/
|
||||
public static function deleteHandle(array $content)
|
||||
public static function deleteHandle(array $content): bool
|
||||
{
|
||||
$result = Typecho_Plugin::factory('Widget_Upload')->trigger($hasDeleted)->deleteHandle($content);
|
||||
$result = Plugin::factory(Upload::class)->trigger($hasDeleted)->deleteHandle($content);
|
||||
if ($hasDeleted) {
|
||||
return $result;
|
||||
}
|
||||
@@ -42,45 +44,46 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
/**
|
||||
* 获取实际文件绝对访问路径
|
||||
*
|
||||
* @access public
|
||||
* @param array $content 文件相关信息
|
||||
* @return string
|
||||
*/
|
||||
public static function attachmentHandle(array $content)
|
||||
public static function attachmentHandle(array $content): string
|
||||
{
|
||||
$result = Typecho_Plugin::factory('Widget_Upload')->trigger($hasPlugged)->attachmentHandle($content);
|
||||
$result = Plugin::factory(Upload::class)->trigger($hasPlugged)->attachmentHandle($content);
|
||||
if ($hasPlugged) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$options = Typecho_Widget::widget('Widget_Options');
|
||||
return Typecho_Common::url($content['attachment']->path,
|
||||
defined('__TYPECHO_UPLOAD_URL__') ? __TYPECHO_UPLOAD_URL__ : $options->siteUrl);
|
||||
$options = self::widget(Options::class);
|
||||
return Common::url(
|
||||
$content['attachment']->path,
|
||||
defined('__TYPECHO_UPLOAD_URL__') ? __TYPECHO_UPLOAD_URL__ : $options->siteUrl
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实际文件数据
|
||||
*
|
||||
* @access public
|
||||
* @param array $content
|
||||
* @return string
|
||||
*/
|
||||
public static function attachmentDataHandle(array $content)
|
||||
public static function attachmentDataHandle(array $content): string
|
||||
{
|
||||
$result = Typecho_Plugin::factory('Widget_Upload')->trigger($hasPlugged)->attachmentDataHandle($content);
|
||||
$result = Plugin::factory(Upload::class)->trigger($hasPlugged)->attachmentDataHandle($content);
|
||||
if ($hasPlugged) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return file_get_contents(Typecho_Common::url($content['attachment']->path,
|
||||
defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__));
|
||||
return file_get_contents(
|
||||
Common::url(
|
||||
$content['attachment']->path,
|
||||
defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function action()
|
||||
{
|
||||
@@ -99,8 +102,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
/**
|
||||
* 执行升级程序
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function modify()
|
||||
{
|
||||
@@ -160,18 +162,17 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
/**
|
||||
* 修改文件处理函数,如果需要实现自己的文件哈希或者特殊的文件系统,请在options表里把modifyHandle改成自己的函数
|
||||
*
|
||||
* @access public
|
||||
* @param array $content 老文件
|
||||
* @param array $file 新上传的文件
|
||||
* @return mixed
|
||||
*/
|
||||
public static function modifyHandle($content, $file)
|
||||
public static function modifyHandle(array $content, array $file)
|
||||
{
|
||||
if (empty($file['name'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = Typecho_Plugin::factory('Widget_Upload')->trigger($hasModified)->modifyHandle($content, $file);
|
||||
$result = Plugin::factory('Widget_Upload')->trigger($hasModified)->modifyHandle($content, $file);
|
||||
if ($hasModified) {
|
||||
return $result;
|
||||
}
|
||||
@@ -182,8 +183,10 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
return false;
|
||||
}
|
||||
|
||||
$path = Typecho_Common::url($content['attachment']->path,
|
||||
defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__);
|
||||
$path = Common::url(
|
||||
$content['attachment']->path,
|
||||
defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__
|
||||
);
|
||||
$dir = dirname($path);
|
||||
|
||||
//创建上传目录
|
||||
@@ -194,7 +197,6 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
}
|
||||
|
||||
if (isset($file['tmp_name'])) {
|
||||
|
||||
@unlink($path);
|
||||
|
||||
//移动上传文件
|
||||
@@ -202,7 +204,6 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
return false;
|
||||
}
|
||||
} elseif (isset($file['bytes'])) {
|
||||
|
||||
@unlink($path);
|
||||
|
||||
//直接写入文件
|
||||
@@ -210,7 +211,6 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
return false;
|
||||
}
|
||||
} elseif (isset($file['bits'])) {
|
||||
|
||||
@unlink($path);
|
||||
|
||||
//直接写入文件
|
||||
@@ -239,11 +239,9 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
* 获取安全的文件名
|
||||
*
|
||||
* @param string $name
|
||||
* @static
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private static function getSafeName(&$name)
|
||||
private static function getSafeName(string &$name): string
|
||||
{
|
||||
$name = str_replace(['"', '<', '>'], '', $name);
|
||||
$name = str_replace('\\', '/', $name);
|
||||
@@ -257,11 +255,10 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
/**
|
||||
* 创建上传路径
|
||||
*
|
||||
* @access private
|
||||
* @param string $path 路径
|
||||
* @return boolean
|
||||
*/
|
||||
private static function makeUploadDir($path)
|
||||
private static function makeUploadDir(string $path): bool
|
||||
{
|
||||
$path = preg_replace("/\\\+/", '/', $path);
|
||||
$current = rtrim($path, '/');
|
||||
@@ -290,8 +287,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
/**
|
||||
* 执行升级程序
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
@@ -355,17 +351,16 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
/**
|
||||
* 上传文件处理函数,如果需要实现自己的文件哈希或者特殊的文件系统,请在options表里把uploadHandle改成自己的函数
|
||||
*
|
||||
* @access public
|
||||
* @param array $file 上传的文件
|
||||
* @return mixed
|
||||
*/
|
||||
public static function uploadHandle($file)
|
||||
public static function uploadHandle(array $file)
|
||||
{
|
||||
if (empty($file['name'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = Typecho_Plugin::factory('Widget_Upload')->trigger($hasUploaded)->uploadHandle($file);
|
||||
$result = Plugin::factory('Widget_Upload')->trigger($hasUploaded)->uploadHandle($file);
|
||||
if ($hasUploaded) {
|
||||
return $result;
|
||||
}
|
||||
@@ -376,10 +371,11 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
return false;
|
||||
}
|
||||
|
||||
$date = new Typecho_Date();
|
||||
$path = Typecho_Common::url(defined('__TYPECHO_UPLOAD_DIR__') ? __TYPECHO_UPLOAD_DIR__ : self::UPLOAD_DIR,
|
||||
defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__)
|
||||
. '/' . $date->year . '/' . $date->month;
|
||||
$date = new Date();
|
||||
$path = Common::url(
|
||||
defined('__TYPECHO_UPLOAD_DIR__') ? __TYPECHO_UPLOAD_DIR__ : self::UPLOAD_DIR,
|
||||
defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__
|
||||
) . '/' . $date->year . '/' . $date->month;
|
||||
|
||||
//创建上传目录
|
||||
if (!is_dir($path)) {
|
||||
@@ -393,19 +389,16 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
$path = $path . '/' . $fileName;
|
||||
|
||||
if (isset($file['tmp_name'])) {
|
||||
|
||||
//移动上传文件
|
||||
if (!@move_uploaded_file($file['tmp_name'], $path)) {
|
||||
return false;
|
||||
}
|
||||
} elseif (isset($file['bytes'])) {
|
||||
|
||||
//直接写入文件
|
||||
if (!file_put_contents($path, $file['bytes'])) {
|
||||
return false;
|
||||
}
|
||||
} elseif (isset($file['bits'])) {
|
||||
|
||||
//直接写入文件
|
||||
if (!file_put_contents($path, $file['bits'])) {
|
||||
return false;
|
||||
@@ -425,7 +418,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
. '/' . $date->year . '/' . $date->month . '/' . $fileName,
|
||||
'size' => $file['size'],
|
||||
'type' => $ext,
|
||||
'mime' => Typecho_Common::mimeContentType($path)
|
||||
'mime' => Common::mimeContentType($path)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -438,7 +431,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
*/
|
||||
public static function checkFileType($ext)
|
||||
{
|
||||
$options = Typecho_Widget::widget('Widget_Options');
|
||||
$options = self::widget(Options::class);
|
||||
return in_array($ext, $options->allowedAttachmentTypes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
|
||||
namespace Widget;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Cookie;
|
||||
use Typecho\Db;
|
||||
use Typecho\Db\Exception as DbException;
|
||||
use Typecho\Widget;
|
||||
use Typecho\Widget\Request;
|
||||
use Typecho\Widget\Response;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登录用户
|
||||
@@ -9,12 +22,11 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_User extends Typecho_Widget
|
||||
class User extends Widget
|
||||
{
|
||||
/**
|
||||
* 用户组
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $groups = [
|
||||
@@ -28,106 +40,102 @@ class Widget_User extends Typecho_Widget
|
||||
/**
|
||||
* 全局选项
|
||||
*
|
||||
* @access protected
|
||||
* @var Widget_Options
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* 数据库对象
|
||||
*
|
||||
* @access protected
|
||||
* @var Typecho_Db
|
||||
* @var Db
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_user;
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* 是否已经登录
|
||||
*
|
||||
* @access private
|
||||
* @var boolean
|
||||
* @var boolean|null
|
||||
*/
|
||||
private $_hasLogin = null;
|
||||
private $hasLogin = null;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param Request $request request对象
|
||||
* @param Response $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @throws DbException
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
public function __construct(Request $request, Response $response, $params = null)
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
|
||||
/** 初始化数据库 */
|
||||
$this->db = Typecho_Db::get();
|
||||
$this->options = $this->widget('Widget_Options');
|
||||
$this->db = Db::get();
|
||||
$this->options = self::widget(Options::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ($this->hasLogin()) {
|
||||
$rows = $this->db->fetchAll($this->db->select()
|
||||
->from('table.options')->where('user = ?', $this->_user['uid']));
|
||||
->from('table.options')->where('user = ?', $this->user['uid']));
|
||||
|
||||
$this->push($this->_user);
|
||||
$this->push($this->user);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$this->options->__set($row['name'], $row['value']);
|
||||
$this->options->{$row['name']} = $row['value'];
|
||||
}
|
||||
|
||||
//更新最后活动时间
|
||||
$this->db->query($this->db
|
||||
->update('table.users')
|
||||
->rows(['activated' => $this->options->time])
|
||||
->where('uid = ?', $this->_user['uid']));
|
||||
->where('uid = ?', $this->user['uid']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否已经登录
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
* @throws DbException
|
||||
*/
|
||||
public function hasLogin()
|
||||
public function hasLogin(): ?bool
|
||||
{
|
||||
if (null !== $this->_hasLogin) {
|
||||
return $this->_hasLogin;
|
||||
if (null !== $this->hasLogin) {
|
||||
return $this->hasLogin;
|
||||
} else {
|
||||
$cookieUid = Typecho_Cookie::get('__typecho_uid');
|
||||
$cookieUid = Cookie::get('__typecho_uid');
|
||||
if (null !== $cookieUid) {
|
||||
/** 验证登陆 */
|
||||
$user = $this->db->fetchRow($this->db->select()->from('table.users')
|
||||
->where('uid = ?', intval($cookieUid))
|
||||
->limit(1));
|
||||
|
||||
$cookieAuthCode = Typecho_Cookie::get('__typecho_authCode');
|
||||
if ($user && Typecho_Common::hashValidate($user['authCode'], $cookieAuthCode)) {
|
||||
$this->_user = $user;
|
||||
return ($this->_hasLogin = true);
|
||||
$cookieAuthCode = Cookie::get('__typecho_authCode');
|
||||
if ($user && Common::hashValidate($user['authCode'], $cookieAuthCode)) {
|
||||
$this->user = $user;
|
||||
return ($this->hasLogin = true);
|
||||
}
|
||||
|
||||
$this->logout();
|
||||
}
|
||||
|
||||
return ($this->_hasLogin = false);
|
||||
return ($this->hasLogin = false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,8 +152,8 @@ class Widget_User extends Typecho_Widget
|
||||
return;
|
||||
}
|
||||
|
||||
Typecho_Cookie::delete('__typecho_uid');
|
||||
Typecho_Cookie::delete('__typecho_authCode');
|
||||
Cookie::delete('__typecho_uid');
|
||||
Cookie::delete('__typecho_authCode');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,8 +165,9 @@ class Widget_User extends Typecho_Widget
|
||||
* @param boolean $temporarily 是否为临时登录
|
||||
* @param integer $expire 过期时间
|
||||
* @return boolean
|
||||
* @throws DbException
|
||||
*/
|
||||
public function login($name, $password, $temporarily = false, $expire = 0)
|
||||
public function login(string $name, string $password, bool $temporarily = false, int $expire = 0): bool
|
||||
{
|
||||
//插件接口
|
||||
$result = $this->pluginHandle()->trigger($loginPluggable)->login($name, $password, $temporarily, $expire);
|
||||
@@ -179,23 +188,22 @@ class Widget_User extends Typecho_Widget
|
||||
$hashValidate = $this->pluginHandle()->trigger($hashPluggable)->hashValidate($password, $user['password']);
|
||||
if (!$hashPluggable) {
|
||||
if ('$P$' == substr($user['password'], 0, 3)) {
|
||||
$hasher = new PasswordHash(8, true);
|
||||
$hasher = new \PasswordHash(8, true);
|
||||
$hashValidate = $hasher->CheckPassword($password, $user['password']);
|
||||
} else {
|
||||
$hashValidate = Typecho_Common::hashValidate($password, $user['password']);
|
||||
$hashValidate = Common::hashValidate($password, $user['password']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user && $hashValidate) {
|
||||
|
||||
if (!$temporarily) {
|
||||
$this->commitLogin($user, $expire);
|
||||
}
|
||||
|
||||
/** 压入数据 */
|
||||
$this->push($user);
|
||||
$this->_user = $user;
|
||||
$this->_hasLogin = true;
|
||||
$this->user = $user;
|
||||
$this->hasLogin = true;
|
||||
$this->pluginHandle()->loginSucceed($this, $name, $password, $temporarily, $expire);
|
||||
|
||||
return true;
|
||||
@@ -208,17 +216,16 @@ class Widget_User extends Typecho_Widget
|
||||
/**
|
||||
* @param $user
|
||||
* @param int $expire
|
||||
*
|
||||
* @throws Typecho_Db_Exception
|
||||
* @throws DbException
|
||||
*/
|
||||
public function commitLogin(&$user, $expire = 0)
|
||||
public function commitLogin(&$user, int $expire = 0)
|
||||
{
|
||||
$authCode = function_exists('openssl_random_pseudo_bytes') ?
|
||||
bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20));
|
||||
bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Common::randString(20));
|
||||
$user['authCode'] = $authCode;
|
||||
|
||||
Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire);
|
||||
Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire);
|
||||
Cookie::set('__typecho_uid', $user['uid'], $expire);
|
||||
Cookie::set('__typecho_authCode', Common::hash($authCode), $expire);
|
||||
|
||||
//更新最后登录时间以及验证码
|
||||
$this->db->query($this->db
|
||||
@@ -231,13 +238,13 @@ class Widget_User extends Typecho_Widget
|
||||
/**
|
||||
* 只需要提供uid或者完整user数组即可登录的方法, 多用于插件等特殊场合
|
||||
*
|
||||
* @access public
|
||||
* @param int | array $uid 用户id或者用户数据数组
|
||||
* @param boolean $temporarily 是否为临时登录,默认为临时登录以兼容以前的方法
|
||||
* @param integer $expire 过期时间
|
||||
* @return boolean
|
||||
* @throws DbException
|
||||
*/
|
||||
public function simpleLogin($uid, $temporarily = true, $expire = 0)
|
||||
public function simpleLogin($uid, bool $temporarily = true, int $expire = 0): bool
|
||||
{
|
||||
if (is_array($uid)) {
|
||||
$user = $uid;
|
||||
@@ -258,8 +265,8 @@ class Widget_User extends Typecho_Widget
|
||||
}
|
||||
|
||||
$this->push($user);
|
||||
$this->_user = $user;
|
||||
$this->_hasLogin = true;
|
||||
$this->user = $user;
|
||||
$this->hasLogin = true;
|
||||
|
||||
$this->pluginHandle()->simpleLoginSucceed($this, $user);
|
||||
return true;
|
||||
@@ -272,9 +279,9 @@ class Widget_User extends Typecho_Widget
|
||||
* @param string $group 用户组
|
||||
* @param boolean $return 是否为返回模式
|
||||
* @return boolean
|
||||
* @throws Typecho_Widget_Exception
|
||||
* @throws DbException|Widget\Exception
|
||||
*/
|
||||
public function pass($group, $return = false)
|
||||
public function pass(string $group, bool $return = false): bool
|
||||
{
|
||||
if ($this->hasLogin()) {
|
||||
if (array_key_exists($group, $this->groups) && $this->groups[$this->group] <= $this->groups[$group]) {
|
||||
@@ -294,7 +301,7 @@ class Widget_User extends Typecho_Widget
|
||||
if ($return) {
|
||||
return false;
|
||||
} else {
|
||||
throw new Typecho_Widget_Exception(_t('禁止访问'), 403);
|
||||
throw new Widget\Exception(_t('禁止访问'), 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* 相关内容
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
namespace Widget\User;
|
||||
|
||||
use Typecho\Db\Exception;
|
||||
use Widget\Base\Users;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 相关内容组件(根据标签关联)
|
||||
@@ -19,13 +18,12 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Widget_Users_Author extends Widget_Abstract_Users
|
||||
class Author extends Users
|
||||
{
|
||||
/**
|
||||
* 执行函数,初始化数据
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
|
||||
@@ -93,10 +93,10 @@ class Widget_Users_Edit extends Widget_Abstract_Users implements Widget_Interfac
|
||||
$user['uid'] = $this->insert($user);
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight('user-' . $user['uid']);
|
||||
self::widget('Widget_Notice')->highlight('user-' . $user['uid']);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('用户 %s 已经被增加', $user['screenName']), 'success');
|
||||
self::widget('Widget_Notice')->set(_t('用户 %s 已经被增加', $user['screenName']), 'success');
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-users.php', $this->options->adminUrl));
|
||||
@@ -243,10 +243,10 @@ class Widget_Users_Edit extends Widget_Abstract_Users implements Widget_Interfac
|
||||
$this->update($user, $this->db->sql()->where('uid = ?', $this->request->uid));
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight('user-' . $this->request->uid);
|
||||
self::widget('Widget_Notice')->highlight('user-' . $this->request->uid);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('用户 %s 已经被更新', $user['screenName']), 'success');
|
||||
self::widget('Widget_Notice')->set(_t('用户 %s 已经被更新', $user['screenName']), 'success');
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('manage-users.php?' .
|
||||
@@ -288,7 +288,7 @@ class Widget_Users_Edit extends Widget_Abstract_Users implements Widget_Interfac
|
||||
}
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('用户已经删除') : _t('没有用户被删除'),
|
||||
self::widget('Widget_Notice')->set($deleteCount > 0 ? _t('用户已经删除') : _t('没有用户被删除'),
|
||||
$deleteCount > 0 ? 'success' : 'notice');
|
||||
|
||||
/** 转向原页 */
|
||||
|
||||
@@ -104,7 +104,7 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
|
||||
*/
|
||||
public function personalFormList()
|
||||
{
|
||||
$this->widget('Widget_Plugins_List@personalPlugins', 'activated=1')->to($plugins);
|
||||
self::widget('Widget_Plugins_List@personalPlugins', 'activated=1')->to($plugins);
|
||||
while ($plugins->next()) {
|
||||
if ($plugins->personalConfig) {
|
||||
[$pluginFileName, $className] = Typecho_Plugin::portal($plugins->name,
|
||||
@@ -181,10 +181,10 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
|
||||
$this->update($user, $this->db->sql()->where('uid = ?', $this->user->uid));
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight('user-' . $this->user->uid);
|
||||
self::widget('Widget_Notice')->highlight('user-' . $this->user->uid);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('您的档案已经更新'), 'success');
|
||||
self::widget('Widget_Notice')->set(_t('您的档案已经更新'), 'success');
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->goBack();
|
||||
@@ -260,10 +260,10 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
|
||||
foreach ($settings as $name => $value) {
|
||||
if ($this->db->fetchObject($this->db->select(['COUNT(*)' => 'num'])
|
||||
->from('table.options')->where('name = ? AND user = ?', $name, $this->user->uid))->num > 0) {
|
||||
$this->widget('Widget_Abstract_Options')
|
||||
self::widget('Widget_Abstract_Options')
|
||||
->update(['value' => $value], $this->db->sql()->where('name = ? AND user = ?', $name, $this->user->uid));
|
||||
} else {
|
||||
$this->widget('Widget_Abstract_Options')->insert([
|
||||
self::widget('Widget_Abstract_Options')->insert([
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
'user' => $this->user->uid
|
||||
@@ -271,7 +271,7 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
|
||||
}
|
||||
}
|
||||
|
||||
$this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("设置已经保存"), 'success');
|
||||
$this->response->goBack();
|
||||
}
|
||||
|
||||
@@ -296,10 +296,10 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
|
||||
$this->db->sql()->where('uid = ?', $this->user->uid));
|
||||
|
||||
/** 设置高亮 */
|
||||
$this->widget('Widget_Notice')->highlight('user-' . $this->user->uid);
|
||||
self::widget('Widget_Notice')->highlight('user-' . $this->user->uid);
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t('密码已经成功修改'), 'success');
|
||||
self::widget('Widget_Notice')->set(_t('密码已经成功修改'), 'success');
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->goBack();
|
||||
@@ -383,10 +383,10 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
|
||||
if (!$this->personalConfigHandle($className, $settings)) {
|
||||
if ($this->db->fetchObject($this->db->select(['COUNT(*)' => 'num'])
|
||||
->from('table.options')->where('name = ? AND user = ?', $name, $this->user->uid))->num > 0) {
|
||||
$this->widget('Widget_Abstract_Options')
|
||||
self::widget('Widget_Abstract_Options')
|
||||
->update(['value' => serialize($settings)], $this->db->sql()->where('name = ? AND user = ?', $name, $this->user->uid));
|
||||
} else {
|
||||
$this->widget('Widget_Abstract_Options')->insert([
|
||||
self::widget('Widget_Abstract_Options')->insert([
|
||||
'name' => $name,
|
||||
'value' => serialize($settings),
|
||||
'user' => $this->user->uid
|
||||
@@ -395,7 +395,7 @@ class Widget_Users_Profile extends Widget_Users_Edit implements Widget_Interface
|
||||
}
|
||||
|
||||
/** 提示信息 */
|
||||
$this->widget('Widget_Notice')->set(_t("%s 设置已经保存", $info['title']), 'success');
|
||||
self::widget('Widget_Notice')->set(_t("%s 设置已经保存", $info['title']), 'success');
|
||||
|
||||
/** 转向原页 */
|
||||
$this->response->redirect(Typecho_Common::url('profile.php', $this->options->adminUrl));
|
||||
|
||||
Reference in New Issue
Block a user