-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.php
167 lines (165 loc) · 4.47 KB
/
function.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
function kumo_Initialization(&$arrJSON = array())
{
global $zbp;
$dir = kumo_Path("cache");
if (!is_dir($dir)) {
@mkdir(dirname($dir));
@mkdir($dir, 0755);
#code
}
$dir = kumo_Path("usr");
$arrJSON = GetFilesInDir($dir, "json");
$_SERVER['kumo_start_time'] = time();
$_SERVER['kumo_debug'] = (bool) $zbp->Config('kumo')->debug;
}
function kumo_debug($line, $msg, $content, $force = 0)
{
if (!$_SERVER['kumo_debug'] && !$force) {
return;
}
echo "{$line}:{$msg}<br>{$content}", "<br><br>\n\n";
echo "-----<br><br>\n\n";
}
function kumo_ReadJSON($name)
{
$dirs = array("proj" => kumo_Path("proj"), "cache" => kumo_Path("cache"));
$obj = new kumoJSON($name, $dirs);
return $obj;
}
function kumo_AddRisuto($arrRisuto)
{
global $zbp;
$arrCount = array("new" => 0, "skip" => 0);
foreach ($arrRisuto as $itemRisuto) {
$obj = new kumo_Risuto();
if (empty($itemRisuto['url'])) {
continue;
}
if ($obj->LoadInfoByField("Url", $itemRisuto['url'])) {
$repeat = 0;
if ($_SERVER['kumo_start_time'] - $obj->Time > 259200) {
$repeat++;
}
if (isset($itemRisuto["repeat"])) {
$repeat += $itemRisuto["repeat"];
}
if ($repeat && $obj->With === $itemRisuto['cur']) {
$repeat++;
}
if ($repeat > 2) {
$obj->Done = false;
$obj->Time = $_SERVER['kumo_start_time'];
kumo_debug(__LINE__, "索引页过期重置", "{$repeat}丨{$obj->Url} - {$obj->With}");
$arrCount["new"]++;
$obj->Save();
} else {
kumo_debug(__LINE__, "已存在", "{$obj->Url} - {$obj->With}<!--{$repeat}-->");
$arrCount["skip"]++;
}
continue;
} else {
$arrCount["new"]++;
}
$obj->Url = $itemRisuto['url'];
$obj->With = $itemRisuto['with'];
$obj->Project = $itemRisuto['project'];
$obj->Save();
kumo_debug(__LINE__, "新增", "{$obj->Url} - {$obj->With}");
}
return "添加:{$arrCount["new"]}丨已存在:{$arrCount["skip"]}";
}
function kumo_GetRisuto($opt = array())
{
global $zbp;
$w[] = array('=', 'rst_Done', 0);
$w[] = array('=', 'rst_Project', $opt["project"]);
// if (isset($opt["order"])) {
// $w[] = array('=', 'rst_With', $opt["order"]);
// }
$limit = isset($opt["num"]) ? $opt["num"] : 57;
$sql = $zbp->db->sql->Select($GLOBALS['table']['kumo_Risuto'], '*', $w, array('rst_ID' => 'asc'), $limit, null);
$arr = $zbp->GetListType("kumo_Risuto", $sql);
$rlt = array();
if (isset($opt["data"])) {
foreach ($arr as $key => $Risuto) {
$rlt[$Risuto->ID] = $Risuto->GetData();
}
} else {
$rlt = $arr;
}
return $rlt;
}
function kumo_DoAct($arr, $act)
{
$title = $arr["title"];
$post = GetPost($title);
$post->Title = $title;
if (stripos($post->Content, $arr["body"]) === false) {
$post->Content .= $arr["body"];
} else {
kumo_debug(__LINE__, "《{$post->Title}》已存在", "");
return;
}
if (!isset($arr["cate"]) || $arr["cate"] == "") {
echo __LINE__ . ":未指定分类\n\n";
} else {
$post->CateID = kumo_GetCate($arr["cate"]);
}
if (isset($arr['intro'])) {
$post->Intro = $arr['intro'];
} else if (empty($post->Intro)) {
$post->Intro = preg_replace('/^((<p>.+?<\/p>){1,5}).+/u', '$1', $post->Content);
$post->Content = str_replace("<p></p>", "", $post->Content);
$post->Content = str_replace("<p><br></p>", "", $post->Content);
$post->Content = str_replace("<br></p>", "", $post->Content);
}
$post->PostTime = time();
$post->AuthorID = kumo_AuthorID($arr["author"]);
return $post->Save();
}
function kumo_GetCate($name, $str = ">>")
{
global $zbp;
$arr = explode($str, $name);
$ParentID = 0;
foreach ($arr as $key => &$itemRisutoalue) {
$itemRisutoalue = trim($itemRisutoalue);
if (empty($itemRisutoalue))
continue;
$result = $zbp->GetCategoryList(null, array(
array(
'=',
'cate_Name',
$itemRisutoalue
),
array(
'=',
'cate_ParentID',
$ParentID
)
), null, 1);
if (count($result) == 0) {
$cate = new Category();
$cate->Name = $itemRisutoalue;
$cate->ParentID = $ParentID;
$cate->Save();
$zbp->LoadCategorys();
} else {
$cate = $result[0];
}
$ParentID = $cate->ID;
}
return $cate->ID;
}
function kumo_AuthorID($name)
{
global $zbp;
$o = $zbp->GetMemberByName($name);
if ($o->ID == 0) {
$o->Name = $name;
$o->Save();
$zbp->LoadMembers();
}
return $o->ID;
}