mirror of
https://github.com/typecho/typecho.git
synced 2025-04-14 06:41:53 +02:00
fix attr
This commit is contained in:
parent
49eed7b437
commit
2fad7cc398
@ -6,3 +6,6 @@ indent_size = 4
|
||||
|
||||
[*.scss]
|
||||
indent_size = 2
|
||||
|
||||
[*.php]
|
||||
insert_final_newline = true
|
@ -77,6 +77,14 @@ class Config implements \Iterator, \ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return empty($this->currentConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重设指针
|
||||
*
|
||||
|
@ -89,6 +89,15 @@ abstract class Widget
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
$this->parameter = Config::factory($params);
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* init method
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,16 +221,11 @@ class Archive extends Contents
|
||||
private $pageNav;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @param mixed $request
|
||||
* @param mixed $response
|
||||
* @param mixed $params
|
||||
* @throws WidgetException|Db\Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
public function init()
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
parent::init();
|
||||
|
||||
$this->parameter->setDefault([
|
||||
'pageSize' => $this->options->pageSize,
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace Widget;
|
||||
|
||||
use Typecho\Db;
|
||||
use Typecho\Db\Query;
|
||||
use Typecho\Plugin;
|
||||
use Typecho\Widget;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
@ -49,68 +49,34 @@ abstract class Base extends Widget
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @throws Db\Exception
|
||||
* init method
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
protected function init()
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
|
||||
/** 初始化数据库 */
|
||||
$this->db = Db::get();
|
||||
|
||||
/** 初始化常用组件 */
|
||||
$this->options = Options::alloc();
|
||||
$this->user = User::alloc();
|
||||
$this->security = Security::alloc();
|
||||
$this->initWith('db', 'options', 'user', 'security');
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询方法
|
||||
* init base component
|
||||
*
|
||||
* @return Query
|
||||
* @param string ...$components
|
||||
*/
|
||||
abstract public function select(): Query;
|
||||
protected function initWith(string ...$components)
|
||||
{
|
||||
if (in_array('db', $components)) {
|
||||
$this->db = Db::get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得所有记录数
|
||||
*
|
||||
* @access public
|
||||
* @param Query $condition 查询对象
|
||||
* @return integer
|
||||
*/
|
||||
abstract public function size(Query $condition): int;
|
||||
if (in_array('options', $components)) {
|
||||
$this->options = Options::alloc();
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加记录方法
|
||||
*
|
||||
* @access public
|
||||
* @param array $rows 字段对应值
|
||||
* @return integer
|
||||
*/
|
||||
abstract public function insert(array $rows): int;
|
||||
if (in_array('user', $components)) {
|
||||
$this->user = User::alloc();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录方法
|
||||
*
|
||||
* @access public
|
||||
* @param array $rows 字段对应值
|
||||
* @param Query $condition 查询对象
|
||||
* @return integer
|
||||
*/
|
||||
abstract public function update(array $rows, Query $condition): int;
|
||||
|
||||
/**
|
||||
* 删除记录方法
|
||||
*
|
||||
* @access public
|
||||
* @param Query $condition 查询对象
|
||||
* @return integer
|
||||
*/
|
||||
abstract public function delete(Query $condition): int;
|
||||
if (in_array('security', $components)) {
|
||||
$this->security = Security::alloc();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,29 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
/**
|
||||
* 评论基类
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @property int $coid
|
||||
* @property int $cid
|
||||
* @property int $created
|
||||
* @property string author
|
||||
* @property int $authorId
|
||||
* @property int $ownerId
|
||||
* @property string $mail
|
||||
* @property string $url
|
||||
* @property string $ip
|
||||
* @property string $agent
|
||||
* @property string $text
|
||||
* @property string $type
|
||||
* @property string status
|
||||
* @property int $parent
|
||||
* @property Date $date
|
||||
* @property string $dateWord
|
||||
* @property string $theId
|
||||
* @property array $parentContent
|
||||
* @property string $title
|
||||
* @property string $permalink
|
||||
* @property string $content
|
||||
*/
|
||||
class Comments extends Base
|
||||
class Comments extends Base implements QueryInterface
|
||||
{
|
||||
/**
|
||||
* 增加评论
|
||||
@ -278,19 +295,6 @@ class Comments extends Base
|
||||
echo Common::subStr(strip_tags($this->content), 0, $length, $trim);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前内容结构
|
||||
*
|
||||
* @return array|null
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function ___parentContent(): ?array
|
||||
{
|
||||
return $this->db->fetchRow(Contents::alloc()->select()
|
||||
->where('table.contents.cid = ?', $this->cid)
|
||||
->limit(1), [Contents::alloc(), 'filter']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询对象
|
||||
*
|
||||
@ -318,6 +322,59 @@ class Comments extends Base
|
||||
->from('table.comments');
|
||||
}
|
||||
|
||||
/**
|
||||
* markdown
|
||||
*
|
||||
* @param string|null $text
|
||||
* @return string
|
||||
*/
|
||||
public function markdown(?string $text): string
|
||||
{
|
||||
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->markdown($text);
|
||||
|
||||
if (!$parsed) {
|
||||
$html = \Markdown::convert($text);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* autoP
|
||||
*
|
||||
* @param string|null $text
|
||||
* @return string
|
||||
*/
|
||||
public function autoP(?string $text): string
|
||||
{
|
||||
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->autoP($text);
|
||||
|
||||
if (!$parsed) {
|
||||
static $parser;
|
||||
|
||||
if (empty($parser)) {
|
||||
$parser = new \AutoP();
|
||||
}
|
||||
|
||||
$html = $parser->parse($text);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前内容结构
|
||||
*
|
||||
* @return array|null
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function ___parentContent(): ?array
|
||||
{
|
||||
return $this->db->fetchRow(Contents::alloc()->select()
|
||||
->where('table.contents.cid = ?', $this->cid)
|
||||
->limit(1), [Contents::alloc(), 'filter']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前评论标题
|
||||
*
|
||||
@ -328,15 +385,6 @@ class Comments extends Base
|
||||
return $this->parentContent['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function ___url(): string
|
||||
{
|
||||
return $this->___permalink();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前评论链接
|
||||
*
|
||||
@ -416,46 +464,6 @@ class Comments extends Base
|
||||
return Common::stripTags($text, '<p><br>' . $this->options->commentsHTMLTagAllowed);
|
||||
}
|
||||
|
||||
/**
|
||||
* markdown
|
||||
*
|
||||
* @param string|null $text
|
||||
* @return string
|
||||
*/
|
||||
public function markdown(?string $text): string
|
||||
{
|
||||
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->markdown($text);
|
||||
|
||||
if (!$parsed) {
|
||||
$html = \Markdown::convert($text);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* autoP
|
||||
*
|
||||
* @param string|null $text
|
||||
* @return string
|
||||
*/
|
||||
public function autoP(?string $text): string
|
||||
{
|
||||
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->autoP($text);
|
||||
|
||||
if (!$parsed) {
|
||||
static $parser;
|
||||
|
||||
if (empty($parser)) {
|
||||
$parser = new \AutoP();
|
||||
}
|
||||
|
||||
$html = $parser->parse($text);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出词义化日期
|
||||
*
|
||||
|
@ -13,6 +13,7 @@ use Typecho\Router;
|
||||
use Typecho\Widget;
|
||||
use Widget\Base;
|
||||
use Widget\Metas\Category\Rows;
|
||||
use Widget\Upload;
|
||||
use Widget\Users\Author;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
@ -22,9 +23,51 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
/**
|
||||
* 内容基类
|
||||
*
|
||||
* @package Widget
|
||||
* @property int $cid
|
||||
* @property string $title
|
||||
* @property string $slug
|
||||
* @property int $created
|
||||
* @property int $modified
|
||||
* @property string $text
|
||||
* @property int $order
|
||||
* @property int $authorId
|
||||
* @property string $template
|
||||
* @property string $type
|
||||
* @property string $status
|
||||
* @property string|null $password
|
||||
* @property int $commentsNum
|
||||
* @property bool $allowComment
|
||||
* @property bool $allowPing
|
||||
* @property bool $allowFeed
|
||||
* @property int $parent
|
||||
* @property int $parentId
|
||||
* @property-read Users $author
|
||||
* @property-read string $permalink
|
||||
* @property-read string $url
|
||||
* @property-read string $feedUrl
|
||||
* @property-read string $feedRssUrl
|
||||
* @property-read string $feedAtomUrl
|
||||
* @property-read bool $isMarkdown
|
||||
* @property-read bool $hidden
|
||||
* @property-read string $category
|
||||
* @property-read Date $date
|
||||
* @property-read string $dateWord
|
||||
* @property-read string[] $directory
|
||||
* @property-read array $tags
|
||||
* @property-read array $categories
|
||||
* @property-read string $description
|
||||
* @property-read string $excerpt
|
||||
* @property-read string $summary
|
||||
* @property-read string $content
|
||||
* @property-read Config $fields
|
||||
* @property-read Config $attachment
|
||||
* @property-read string $theId
|
||||
* @property-read string $respondId
|
||||
* @property-read string $commentUrl
|
||||
* @property-read string $trackbackUrl
|
||||
* @property-read string $responseUrl
|
||||
*/
|
||||
class Contents extends Base
|
||||
class Contents extends Base implements QueryInterface
|
||||
{
|
||||
/**
|
||||
* 获取查询对象
|
||||
@ -505,7 +548,7 @@ class Contents extends Base
|
||||
//增加数据信息
|
||||
$value['attachment'] = new Config($content);
|
||||
$value['attachment']->isImage = in_array($content['type'], ['jpg', 'jpeg', 'gif', 'png', 'tiff', 'bmp']);
|
||||
$value['attachment']->url = Widget_Upload::attachmentHandle($value);
|
||||
$value['attachment']->url = Upload::attachmentHandle($value);
|
||||
|
||||
if ($value['attachment']->isImage) {
|
||||
$value['text'] = '<img src="' . $value['attachment']->url . '" alt="' .
|
||||
|
@ -15,12 +15,22 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
/**
|
||||
* 描述性数据组件
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @property int $mid
|
||||
* @property string $name
|
||||
* @property string $slug
|
||||
* @property string $type
|
||||
* @property string $description
|
||||
* @property int $count
|
||||
* @property int $order
|
||||
* @property int $parent
|
||||
* @property-read string $theId
|
||||
* @property-read string $url
|
||||
* @property-read string $permalink
|
||||
* @property-read string $feedUrl
|
||||
* @property-read string $feedRssUrl
|
||||
* @property-read string $feedAtomUrl
|
||||
*/
|
||||
class Metas extends Base
|
||||
class Metas extends Base implements QueryInterface
|
||||
{
|
||||
/**
|
||||
* 获取记录总数
|
||||
|
@ -18,7 +18,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Options extends Base
|
||||
class Options extends Base implements QueryInterface
|
||||
{
|
||||
/**
|
||||
* 获取原始查询对象
|
||||
|
55
var/Widget/Base/QueryInterface.php
Normal file
55
var/Widget/Base/QueryInterface.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Widget\Base;
|
||||
|
||||
use Typecho\Db\Query;
|
||||
|
||||
/**
|
||||
* Base Query Interface
|
||||
*/
|
||||
interface QueryInterface
|
||||
{
|
||||
/**
|
||||
* 查询方法
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
public function select(): Query;
|
||||
|
||||
/**
|
||||
* 获得所有记录数
|
||||
*
|
||||
* @access public
|
||||
* @param Query $condition 查询对象
|
||||
* @return integer
|
||||
*/
|
||||
public function size(Query $condition): int;
|
||||
|
||||
/**
|
||||
* 增加记录方法
|
||||
*
|
||||
* @access public
|
||||
* @param array $rows 字段对应值
|
||||
* @return integer
|
||||
*/
|
||||
public function insert(array $rows): int;
|
||||
|
||||
/**
|
||||
* 更新记录方法
|
||||
*
|
||||
* @access public
|
||||
* @param array $rows 字段对应值
|
||||
* @param Query $condition 查询对象
|
||||
* @return integer
|
||||
*/
|
||||
public function update(array $rows, Query $condition): int;
|
||||
|
||||
/**
|
||||
* 删除记录方法
|
||||
*
|
||||
* @access public
|
||||
* @param Query $condition 查询对象
|
||||
* @return integer
|
||||
*/
|
||||
public function delete(Query $condition): int;
|
||||
}
|
@ -16,12 +16,24 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
/**
|
||||
* 用户抽象类
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @property int $uid
|
||||
* @property string $name
|
||||
* @property string $password
|
||||
* @property string $mail
|
||||
* @property string $url
|
||||
* @property string $screenName
|
||||
* @property int $created
|
||||
* @property int $activated
|
||||
* @property int $logged
|
||||
* @property string $group
|
||||
* @property string $authCode
|
||||
* @property-read Config $options
|
||||
* @property-read string $permalink
|
||||
* @property-read string $feedUrl
|
||||
* @property-read string $feedRssUrl
|
||||
* @property-read string $feedAtomUrl
|
||||
*/
|
||||
class Users extends Base
|
||||
class Users extends Base implements QueryInterface
|
||||
{
|
||||
/**
|
||||
* 判断用户名称是否存在
|
||||
@ -112,7 +124,7 @@ class Users extends Base
|
||||
//生成静态链接
|
||||
$routeExists = (null != Router::get('author'));
|
||||
|
||||
$value['url'] = $value['permalink'] = $routeExists ? Router::url('author', $value, $this->options->index) : '#';
|
||||
$value['permalink'] = $routeExists ? Router::url('author', $value, $this->options->index) : '#';
|
||||
|
||||
/** 生成聚合链接 */
|
||||
/** RSS 2.0 */
|
||||
|
@ -114,7 +114,7 @@ class Edit extends PostEdit implements ActionInterface
|
||||
$attachment['title'] = $input['name'];
|
||||
$attachment['slug'] = $input['slug'];
|
||||
|
||||
$content = unserialize($this->attachment->__toString());
|
||||
$content = $this->attachment->toArray();
|
||||
$content['description'] = $input['description'];
|
||||
|
||||
$attachment['text'] = serialize($content);
|
||||
|
@ -95,7 +95,7 @@ class Date extends Widget
|
||||
$row['permalink'] = Router::url(
|
||||
'archive_' . $this->parameter->type,
|
||||
$row,
|
||||
self::widget('Widget_Options')->index
|
||||
$this->options->index
|
||||
);
|
||||
$this->push($row);
|
||||
}
|
||||
|
@ -23,11 +23,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
/**
|
||||
* 编辑文章组件
|
||||
*
|
||||
* @author qining
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @property-read array|null $draft
|
||||
*/
|
||||
class Edit extends Contents implements ActionInterface
|
||||
{
|
||||
@ -1021,10 +1017,10 @@ class Edit extends Contents implements ActionInterface
|
||||
/**
|
||||
* 当前文章的草稿
|
||||
*
|
||||
* @return array
|
||||
* @return array|null
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function ___draft()
|
||||
protected function ___draft(): ?array
|
||||
{
|
||||
if ($this->have()) {
|
||||
if ('post_draft' == $this->type) {
|
||||
@ -1044,4 +1040,3 @@ class Edit extends Contents implements ActionInterface
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,14 +15,13 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class ExceptionHandle extends Widget_Archive
|
||||
class ExceptionHandle extends Base
|
||||
{
|
||||
/**
|
||||
* 重载构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
public function execute()
|
||||
{
|
||||
self::widget('Widget_Archive@404', 'type=404')->render();
|
||||
exit;
|
||||
Archive::allocWithAlias('404', 'type=404')->render();
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class Init extends Widget
|
||||
});
|
||||
|
||||
if (404 == $exception->getCode()) {
|
||||
new ExceptionHandle($exception);
|
||||
ExceptionHandle::alloc();
|
||||
} else {
|
||||
Common::error($exception);
|
||||
}
|
||||
|
@ -19,12 +19,46 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
/**
|
||||
* 全局选项组件
|
||||
*
|
||||
* @link typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
* @property-read string $feedUrl
|
||||
* @property-read string $feedRssUrl
|
||||
* @property-read string $feedAtomUrl
|
||||
* @property-read string $commentsFeedUrl
|
||||
* @property-read string $commentsFeedRssUrl
|
||||
* @property-read string $commentsFeedAtomUrl
|
||||
* @property-read string $themeUrl
|
||||
* @property-read string $xmlRpcUrl
|
||||
* @property-read string $index
|
||||
* @property-read string $siteUrl
|
||||
* @property-read array $routingTable
|
||||
* @property-read string $rootUrl
|
||||
* @property-read string $pluginUrl
|
||||
* @property-read string $adminUrl
|
||||
* @property-read string $loginUrl
|
||||
* @property-read string $loginAction
|
||||
* @property-read string $registerUrl
|
||||
* @property-read string $registerAction
|
||||
* @property-read string $profileUrl
|
||||
* @property-read string $logoutUrl
|
||||
* @property-read string $title
|
||||
* @property-read string $description
|
||||
* @property-read string $keywords
|
||||
* @property-read string $lang
|
||||
* @property-read string $theme
|
||||
* @property-read int $pageSize
|
||||
* @property-read int $serverTimezone
|
||||
* @property-read int $timezone
|
||||
* @property-read string $charset
|
||||
* @property-read string $contentType
|
||||
* @property-read string $software
|
||||
* @property-read string $version
|
||||
* @property-read bool $markdown
|
||||
* @property-read bool $xmlrpcMarkdown
|
||||
* @property-read array $allowedAttachmentTypes
|
||||
* @property-read string $attachmentTypes
|
||||
* @property-read int $time
|
||||
* @property-read string $frontPage
|
||||
*/
|
||||
class Options extends Widget
|
||||
class Options extends Base
|
||||
{
|
||||
/**
|
||||
* 数据库对象
|
||||
@ -53,21 +87,15 @@ class Options extends Widget
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @param mixed $request request对象
|
||||
* @param mixed $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @throws DbException
|
||||
*/
|
||||
public function __construct($request, $response, $params = null)
|
||||
public function init()
|
||||
{
|
||||
parent::__construct($request, $response);
|
||||
|
||||
if (!empty($params)) {
|
||||
if (!$this->parameter->isEmpty()) {
|
||||
// 使用参数初始化而不使用数据库
|
||||
$this->row = $params;
|
||||
$this->row = $this->parameter->toArray();
|
||||
} else {
|
||||
/** 初始化数据库 */
|
||||
$this->db = Db::get();
|
||||
$this->initWith('db');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class User extends Widget
|
||||
class User extends Base
|
||||
{
|
||||
/**
|
||||
* 用户组
|
||||
@ -56,7 +56,7 @@ class User extends Widget
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $user;
|
||||
private $currentUser;
|
||||
|
||||
/**
|
||||
* 是否已经登录
|
||||
@ -66,23 +66,13 @@ class User extends Widget
|
||||
private $hasLogin = null;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化组件
|
||||
*
|
||||
* @param Request $request request对象
|
||||
* @param Response $response response对象
|
||||
* @param mixed $params 参数列表
|
||||
* @throws DbException
|
||||
* init method
|
||||
*/
|
||||
public function __construct(Request $request, Response $response, $params = null)
|
||||
protected function init()
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
|
||||
/** 初始化数据库 */
|
||||
$this->db = Db::get();
|
||||
$this->options = Options::alloc();
|
||||
$this->initWith('db', 'options');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
@ -92,9 +82,9 @@ class User extends Widget
|
||||
{
|
||||
if ($this->hasLogin()) {
|
||||
$rows = $this->db->fetchAll($this->db->select()
|
||||
->from('table.options')->where('user = ?', $this->user['uid']));
|
||||
->from('table.options')->where('user = ?', $this->currentUser['uid']));
|
||||
|
||||
$this->push($this->user);
|
||||
$this->push($this->currentUser);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$this->options->{$row['name']} = $row['value'];
|
||||
@ -104,7 +94,7 @@ class User extends Widget
|
||||
$this->db->query($this->db
|
||||
->update('table.users')
|
||||
->rows(['activated' => $this->options->time])
|
||||
->where('uid = ?', $this->user['uid']));
|
||||
->where('uid = ?', $this->currentUser['uid']));
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,7 +118,7 @@ class User extends Widget
|
||||
|
||||
$cookieAuthCode = Cookie::get('__typecho_authCode');
|
||||
if ($user && Common::hashValidate($user['authCode'], $cookieAuthCode)) {
|
||||
$this->user = $user;
|
||||
$this->currentUser = $user;
|
||||
return ($this->hasLogin = true);
|
||||
}
|
||||
|
||||
@ -202,7 +192,7 @@ class User extends Widget
|
||||
|
||||
/** 压入数据 */
|
||||
$this->push($user);
|
||||
$this->user = $user;
|
||||
$this->currentUser = $user;
|
||||
$this->hasLogin = true;
|
||||
$this->pluginHandle()->loginSucceed($this, $name, $password, $temporarily, $expire);
|
||||
|
||||
@ -265,7 +255,7 @@ class User extends Widget
|
||||
}
|
||||
|
||||
$this->push($user);
|
||||
$this->user = $user;
|
||||
$this->currentUser = $user;
|
||||
$this->hasLogin = true;
|
||||
|
||||
$this->pluginHandle()->simpleLoginSucceed($this, $user);
|
||||
|
@ -554,12 +554,12 @@ class XmlRpc extends Contents implements ActionInterface, Hook
|
||||
* @return bool
|
||||
*/
|
||||
public function wpEditPage(
|
||||
int $blogId,
|
||||
int $pageId,
|
||||
int $blogId,
|
||||
int $pageId,
|
||||
string $userName,
|
||||
string $password,
|
||||
array $content,
|
||||
bool $publish
|
||||
array $content,
|
||||
bool $publish
|
||||
) {
|
||||
$content['post_type'] = 'page';
|
||||
$this->mwEditPost($pageId, $userName, $password, $content, $publish);
|
||||
@ -677,11 +677,11 @@ class XmlRpc extends Contents implements ActionInterface, Hook
|
||||
* @throws \Typecho\Db\Exception
|
||||
*/
|
||||
public function wpSuggestCategories(
|
||||
int $blogId,
|
||||
int $blogId,
|
||||
string $userName,
|
||||
string $password,
|
||||
string $category,
|
||||
int $maxResults = 0
|
||||
int $maxResults = 0
|
||||
): array {
|
||||
/** 构造出查询语句并且查询*/
|
||||
$key = Common::filterSearchQuery($category);
|
||||
@ -1743,16 +1743,16 @@ class XmlRpc extends Contents implements ActionInterface, Hook
|
||||
|
||||
if ($pingNum <= 0) {
|
||||
try {
|
||||
$pingback = new Pingback($source, $target);
|
||||
$pingbackRequest = new Pingback($source, $target);
|
||||
|
||||
$pingback = [
|
||||
'cid' => $post->cid,
|
||||
'created' => $this->options->time,
|
||||
'agent' => $this->request->getAgent(),
|
||||
'ip' => $this->request->getIp(),
|
||||
'author' => $pingback->getTitle(),
|
||||
'author' => $pingbackRequest->getTitle(),
|
||||
'url' => Common::safeUrl($source),
|
||||
'text' => $pingback->getContent(),
|
||||
'text' => $pingbackRequest->getContent(),
|
||||
'ownerId' => $post->author->uid,
|
||||
'type' => 'pingback',
|
||||
'status' => $this->options->commentsRequireModeration ? 'waiting' : 'approved'
|
||||
@ -1770,6 +1770,8 @@ class XmlRpc extends Contents implements ActionInterface, Hook
|
||||
return $insertId;
|
||||
} catch (Exception $e) {
|
||||
return new Error(16, _t('源地址服务器错误'));
|
||||
} catch (\IXR\Exception $e) {
|
||||
return new Error(50, _t('源地址不支持PingBack'));
|
||||
}
|
||||
} else {
|
||||
return new Error(48, _t('PingBack已经存在'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user