Skip to content

Commit

Permalink
fix #1671 (#1678)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Jan 4, 2024
1 parent d520a55 commit 81ad223
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 50 deletions.
11 changes: 5 additions & 6 deletions admin/manage-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,13 @@ class="i-exlink"></i></a>
<td class="kit-hidden-mb"><a
href="<?php $options->adminUrl('manage-posts.php?__typecho_all_posts=off&uid=' . $posts->author->uid); ?>"><?php $posts->author(); ?></a>
</td>
<td class="kit-hidden-mb"><?php $categories = $posts->categories;
while ($categories->next()): ?>
<?php echo '<a href="';
$options->adminUrl('manage-posts.php?category=' . $categories->mid
<td class="kit-hidden-mb"><?php foreach($posts->categories as $index => $category): ?><!--
--><?php echo ($index > 0 ? ', ' : '') . '<a href="';
$options->adminUrl('manage-posts.php?category=' . $category['mid']
. (isset($request->uid) ? '&uid=' . $request->filter('encode')->uid : '')
. (isset($request->status) ? '&status=' . $request->filter('encode')->status : ''));
echo '">' . $categories->name . '</a>' . ($categories->sequence < $categories->length - 1 ? ', ' : ''); ?>
<?php endwhile; ?>
echo '">' . $category['name'] . '</a>'; ?><!--
--><?php endforeach; ?>
</td>
<td>
<?php if ('post_draft' == $posts->type || $posts->revision): ?>
Expand Down
2 changes: 1 addition & 1 deletion admin/write-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class="btn"><?php _e('保存草稿'); ?></button>
<label class="typecho-label"><?php _e('分类'); ?></label>
<?php \Widget\Metas\Category\Rows::alloc()->to($category); ?>
<ul>
<?php $categories = $post->categories->toArray('mid'); ?>
<?php $categories = array_column($post->categories, 'mid'); ?>
<?php while ($category->next()): ?>
<li><?php echo str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $category->levels); ?><input
type="checkbox" id="category-<?php $category->mid(); ?>"
Expand Down
17 changes: 16 additions & 1 deletion var/Typecho/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ public function push(array $value)
return $value;
}

/**
* 将所有行的值压入堆栈
*
* @param array $values 所有行的值
*/
public function pushAll(array $values)
{
foreach ($values as $value) {
$this->push($value);
}
}

/**
* 根据余数输出
*
Expand Down Expand Up @@ -471,7 +483,10 @@ public function __set(string $name, $value)
*/
public function __isSet(string $name)
{
return isset($this->row[$name]);
$method = '___' . $name;
$key = '#' . $name;

return isset($this->row[$key]) || method_exists($this, $method) || isset($this->row[$name]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ private function singleHandle(Query $select, bool &$hasPushed)
$this->archiveTitle = $this->title;

/** 设置关键词 */
$this->archiveKeywords = implode(',', $this->tags->toArray('name'));
$this->archiveKeywords = implode(',', array_column($this->tags, 'name'));

/** 设置描述 */
$this->archiveDescription = $this->plainExcerpt;
Expand Down
44 changes: 20 additions & 24 deletions var/Widget/Base/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
* @property-read Date $date
* @property-read string $dateWord
* @property-read string[] $directory
* @property-read Metas $tags
* @property-read Metas $categories
* @property-read array[] $tags
* @property-read array[] $categories
* @property-read string $excerpt
* @property-read string $plainExcerpt
* @property-read string $summary
Expand Down Expand Up @@ -95,7 +95,7 @@ public function getRouterParam(string $key): string
case 'directory':
return implode('/', array_map('urlencode', $this->directory));
case 'category':
return urlencode($this->categories->slug);
return empty($this->categories) ? '' : urlencode($this->categories[0]['slug']);
case 'year':
return $this->date->year;
case 'month':
Expand Down Expand Up @@ -461,13 +461,11 @@ public function allow(...$permissions): bool
*/
public function category(string $split = ',', bool $link = true, ?string $default = null)
{
$categories = $this->categories;

if ($categories->have()) {
if (!empty($this->categories)) {
$result = [];

while ($categories->next()) {
$result[] = $link ? $categories->template('<a href="{permalink}">{name}</a>') : $categories->name;
foreach ($this->categories as $category) {
$result[] = $link ? "<a href=\"{$category['permalink']}\">{$category['name']}</a>" : $category['name'];
}

echo implode($split, $result);
Expand Down Expand Up @@ -513,13 +511,11 @@ public function directory(string $split = '/', bool $link = true, ?string $defau
*/
public function tags(string $split = ',', bool $link = true, ?string $default = null)
{
$tags = $this->tags;

if ($tags->have()) {
if (!empty($this->tags)) {
$result = [];

while ($tags->next()) {
$result[] = $link ? $tags->template('<a href="{permalink}">{name}</a>') : $tags->name;
foreach ($this->tags as $tag) {
$result[] = $link ? "<a href=\"{$tag['permalink']}\">{$tag['name']}</a>" : $tag['name'];
}

echo implode($split, $result);
Expand Down Expand Up @@ -658,32 +654,32 @@ protected function ___directory(): array
{
$directory = [];

$category = $this->categories;

if ($category->have()) {
$directory = Rows::alloc()->getAllParentsSlug($category->mid);
$directory[] = $category->slug;
if (!empty($this->categories)) {
$directory = Rows::alloc()->getAllParentsSlug($this->categories[0]['mid']);
$directory[] = $this->categories[0]['slug'];
}

return $directory;
}

/**
* @return Metas
* @return array
*/
protected function ___categories(): Metas
protected function ___categories(): array
{
return CategoryRelated::allocWithAlias($this->cid, ['cid' => $this->cid]);
return CategoryRelated::allocWithAlias($this->cid, ['cid' => $this->cid])
->toArray(['mid', 'name', 'slug', 'description', 'order', 'parent', 'count', 'permalink']);
}

/**
* 将tags取出
*
* @return Metas
* @return array
*/
protected function ___tags(): Metas
protected function ___tags(): array
{
return TagRelated::allocWithAlias($this->cid, ['cid' => $this->cid]);
return TagRelated::allocWithAlias($this->cid, ['cid' => $this->cid])
->toArray(['mid', 'name', 'slug', 'description', 'count', 'permalink']);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions var/Widget/Contents/Page/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,18 @@ public function execute()
$this->parameter->setDefault('ignoreRequest=0');

if ($this->parameter->ignoreRequest) {
$this->stack = $this->getRows($this->orders, $this->parameter->ignore);
$this->pushAll($this->getRows($this->orders, $this->parameter->ignore));
} elseif ($this->request->is('keywords')) {
$select = $this->select('table.contents.cid')
->where('table.contents.type = ? OR table.contents.type = ?', 'page', 'page_draft');
$this->searchQuery($select);

$ids = array_column($this->db->fetchAll($select), 'cid');
$this->stack = $this->getRows($ids);
$this->pushAll($this->getRows($ids));
} else {
$this->parentId = $this->request->filter('int')->get('parent', 0);
$this->stack = $this->getRows($this->getChildIds($this->parentId));
$this->pushAll($this->getRows($this->getChildIds($this->parentId)));
}

$this->row = reset($this->stack);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions var/Widget/Contents/Page/Rows.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class Rows extends Contents
*/
public function execute()
{
$this->stack = $this->getRows($this->orders, $this->parameter->ignore);
$this->row = reset($this->stack);
$this->pushAll($this->getRows($this->orders, $this->parameter->ignore));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions var/Widget/Contents/PrepareEditTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ protected function ___text(): string
}

/**
* @return Metas
* @return array
*/
protected function ___categories(): Metas
protected function ___categories(): array
{
return $this->have() ? parent::___categories()
: MetasFrom::allocWithAlias(
'category:' . $this->options->defaultCategory,
['mid' => $this->options->defaultCategory]
);
)->toArray(['mid', 'name', 'slug']);
}
}
2 changes: 1 addition & 1 deletion var/Widget/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function feed(
'link' => $archive->permalink,
'author' => $archive->author,
'excerpt' => $archive->plainExcerpt,
'category' => $archive->categories->toArray(['name', 'permalink']),
'category' => $archive->categories,
'comments' => $archive->commentsNum,
'commentsFeedUrl' => Common::url($archive->path, $feed->getFeedUrl()),
'suffix' => $suffix
Expand Down
3 changes: 1 addition & 2 deletions var/Widget/Metas/Category/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class Admin extends Metas
public function execute()
{
$this->parentId = $this->request->filter('int')->get('parent', 0);
$this->stack = $this->getRows($this->getChildIds($this->parentId));
$this->row = reset($this->stack);
$this->pushAll($this->getRows($this->getChildIds($this->parentId)));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions var/Widget/Metas/Category/Related.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function execute()
return $orderA <=> $orderB;
});

$this->stack = $this->getRows($ids);
$this->row = reset($this->stack);
$this->pushAll($this->getRows($ids));
}
}
3 changes: 1 addition & 2 deletions var/Widget/Metas/Category/Rows.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class Rows extends Metas
*/
public function execute()
{
$this->stack = $this->getRows($this->orders, $this->parameter->ignore);
$this->row = reset($this->stack);
$this->pushAll($this->getRows($this->orders, $this->parameter->ignore));
}

/**
Expand Down

0 comments on commit 81ad223

Please sign in to comment.