forked from unpush/p2-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo_js.php
264 lines (230 loc) · 7.02 KB
/
info_js.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
/**
* rep2 - 板・スレッド情報をJSON形式で返す
*/
require_once './conf/conf.inc.php';
require_once P2_LIB_DIR . '/P2Util.php';
require_once P2_LIB_DIR . '/Thread.php';
$_login->authorize(); // ユーザ認証
$host = isset($_GET['host']) ? $_GET['host'] : null; // "pc.2ch.net"
$bbs = isset($_GET['bbs']) ? $_GET['bbs'] : null; // "php"
$key = isset($_GET['key']) ? $_GET['key'] : null; // "1022999539"
header('Content-Type: application/json; charset=UTF-8');
if (!$host || !$bbs) {
echo 'null';
} elseif (!$key) {
echo info_js_get_board_info($host, $bbs);
} else {
echo info_js_get_thread_info($host, $bbs, $key);
}
// {{{ info_js_get_board_info()
/**
* 板情報を取得する
*
* @param string $host
* @param string $bbs
* @return string JSONエンコードされた板情報
*/
function info_js_get_board_info($host, $bbs)
{
global $_conf;
$group = P2Util::getHostGroupName($host);
$info = new stdClass();
$info->type = 'board';
$info->group = $group;
$info->host = $host;
$info->bbs = $bbs;
// 板名を取得
$itaj = P2Util::getItaName($host, $bbs);
if (!$itaj) {
if (isset($_GET['itaj_en'])) {
$itaj = base64_decode($_GET['itaj_en']);
} else {
$itaj = $bbs;
}
}
$info->itaj = $itaj;
// お気に板登録状況を取得
$favs = array();
if ($_conf['expack.misc.multi_favs']) {
$favita_titles = FavSetManager::getFavSetTitles('m_favita_set');
for ($i = 0; $i <= $_conf['expack.misc.favset_num']; $i++) {
if (!isset($favita_titles[$i]) || $favita_titles[$i] == '') {
if ($i == 0) {
$favtitle = 'お気に板';
} else {
$favtitle = "お気に板{$i}";
}
} else {
$favtitle = $favita_titles[$i];
}
$favs[$i] = array('title' => $favtitle, 'set' => false);
}
$favitas = $_conf['favitas'];
} else {
$favs[0] = array('title' => 'お気に板', 'set' => false);
$favitas = array(array());
if ($favlines = FileCtl::file_read_lines($_conf['favita_brd'], FILE_IGNORE_NEW_LINES)) {
foreach ($favlines as $l) {
$lar = explode("\t", $l);
$favitas[0][] = array(
'group' => P2Util::getHostGroupName($lar[1]),
'host' => $lar[1],
'bbs' => $lar[2],
'itaj' => $lar[3]
);
}
}
}
foreach ($favitas as $num => $favita) {
foreach ($favita as $ita) {
if ($bbs == $ita['bbs'] && $group == $ita['group']) {
$favs[$num]['set'] = true;
break;
}
}
}
$info->favs = $favs;
return info_js_json_encode($info);
}
// }}}
// {{{ info_js_get_thread_info()
/**
* スレッド情報を取得する
*
* @param string $host
* @param string $bbs
* @param string $key
* @return string JSONエンコードされたスレッド情報
*/
function info_js_get_thread_info($host, $bbs, $key)
{
global $_conf;
$group = P2Util::getHostGroupName($host);
$info = new stdClass();
$info->type = 'thread';
$info->group = $group;
$info->host = $host;
$info->bbs = $bbs;
$info->key = $key;
$aThread = new Thread();
// hostを分解してidxファイルのパスを求める
$aThread->setThreadPathInfo($host, $bbs, $key);
$key_line = $aThread->getThreadInfoFromIdx();
// $aThread->length をset
$aThread->getDatBytesFromLocalDat();
// 板名を取得
$aThread->itaj = P2Util::getItaName($host, $bbs);
if (!$aThread->itaj) {
if (isset($_GET['itaj_en'])) {
$aThread->itaj = base64_decode($_GET['itaj_en']);
} else {
$aThread->itaj = $bbs;
}
}
$info->itaj = $aThread->itaj;
// スレタイトルを取得
if (!$aThread->ttitle) {
if (isset($_GET['ttitle_en'])) {
$aThread->setTtitle(base64_decode($_GET['ttitle_en']));
} else {
$aThread->setTitleFromLocal();
}
}
$info->ttitle = $aThread->ttitle;
// お気にスレ登録状況を取得
$favs = array();
if ($_conf['expack.misc.multi_favs']) {
$favlist_titles = FavSetManager::getFavSetTitles('m_favlist_set');
for ($i = 0; $i <= $_conf['expack.misc.favset_num']; $i++) {
if (!isset($favlist_titles[$i]) || $favlist_titles[$i] == '') {
if ($i == 0) {
$favtitle = 'お気にスレ';
} else {
$favtitle = "お気にスレ{$i}";
}
} else {
$favtitle = $favlist_titles[$i];
}
$favs[$i] = array('title' => $favtitle, 'set' => !empty($aThread->favs[$i]));
}
} else {
$favs[0] = array('title' => 'お気にスレ', 'set' => !empty($aThread->fav));
}
$info->favs = $favs;
// 殿堂チェック
$info->palace = false;
if ($pallines = FileCtl::file_read_lines($_conf['palace_idx'], FILE_IGNORE_NEW_LINES)) {
foreach ($pallines as $l) {
$palarray = explode('<>', $l);
if ($aThread->key == $palarray[1] && $aThread->bbs == $palarray[11]) {
if (P2Util::getHostGroupName($palarray[10]) == $group) {
$info->palace = true;
break;
}
}
}
}
// スレッドあぼーんチェック
$info->taborn = false;
$taborn_idx = P2Util::idxDirOfHostBbs($host, $bbs) . 'p2_threads_aborn.idx';
if ($tabornlines = FileCtl::file_read_lines($taborn_idx, FILE_IGNORE_NEW_LINES)) {
foreach ($tabornlines as $l) {
$tabornarray = explode('<>', $l);
if ($aThread->key == $tabornarray[1] && $aThread->bbs == $tabornarray[11]) {
if (P2Util::getHostGroupName($tabornarray[10]) == $group) {
$info->taborn = true;
break;
}
}
}
}
// ログ関連
$hasLog = false;
if (file_exists($aThread->keydat)) {
$info->keydat = $aThread->keydat;
$info->length = $aThread->length;
$hasLog = true;
} else {
$info->keydat = null;
$info->length = -1;
}
if (file_exists($aThread->keyidx)) {
$info->keyidx = $aThread->keyidx;
$hasLog = true;
} else {
$info->keyidx = null;
}
if ($aThread->gotnum) {
$info->gotnum = $aThread->gotnum;
} elseif ($hasLog) {
$info->gotnum = 0;
} else {
$info->gotnum = -1;
}
return info_js_json_encode($info);
}
// }}}
// {{{ info_js_json_encode()
/**
* Shift_JISの値をUTF-8に変換してからJSONエンコードする
*
* @param mixed $values
* @return string JSON
*/
function info_js_json_encode($values)
{
mb_convert_variables('UTF-8', 'CP932', $values);
return json_encode($values);
}
// }}}
/*
* Local Variables:
* mode: php
* coding: cp932
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker: