forked from typecho/typecho
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrom.php
92 lines (81 loc) · 2.13 KB
/
From.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Widget\Contents;
use Typecho\Config;
use Typecho\Db\Exception;
use Widget\Base\Contents;
use Widget\Base\TreeTrait;
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
/**
* 单个内容组件
*/
class From extends Contents
{
use TreeTrait {
initParameter as initTreeParameter;
___directory as ___treeDirectory;
}
/**
* @param Config $parameter
* @return void
*/
protected function initParameter(Config $parameter)
{
$parameter->setDefault([
'cid' => null,
'query' => null,
]);
}
/**
* @return void
* @throws Exception
*/
public function execute()
{
$query = null;
if (isset($this->parameter->cid)) {
$query = $this->select()->where('cid = ?', $this->parameter->cid);
} elseif (isset($this->parameter->query)) {
$query = $this->parameter->query;
}
if ($query) {
$this->db->fetchAll($query, [$this, 'push']);
if ($this->type == 'page') {
$this->initTreeParameter($this->parameter);
}
}
}
/**
* @return array
*/
protected function ___directory(): array
{
return $this->type == 'page' ? $this->___treeDirectory() : parent::___directory();
}
/**
* @return array
* @throws Exception
*/
protected function initTreeRows(): array
{
return $this->db->fetchAll($this->select(
'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.commentsNum',
'table.contents.order',
'table.contents.parent',
'table.contents.template',
'table.contents.password',
'table.contents.allowComment',
'table.contents.allowPing',
'table.contents.allowFeed'
)->where('table.contents.type = ?', 'page'));
}
}