forked from unpush/p2-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ic2_manager.php
203 lines (175 loc) · 7.14 KB
/
ic2_manager.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
<?php
/**
* ImageCache2 - メンテナンス
*/
// {{{ p2基本設定読み込み&認証
define('P2_OUTPUT_XHTML', 1);
require_once './conf/conf.inc.php';
$_login->authorize();
if (!$_conf['expack.ic2.enabled']) {
p2die('ImageCache2は無効です。', 'conf/conf_admin_ex.inc.php の設定を変えてください。');
}
// }}}
// {{{ 初期化
// ライブラリ読み込み
require_once 'PEAR.php';
require_once 'DB.php';
require_once 'HTML/Template/Flexy.php';
require_once P2EX_LIB_DIR . '/ic2/loadconfig.inc.php';
// 設定読み込み
$ini = ic2_loadconfig();
// データベースに接続
$db = DB::connect($ini['General']['dsn']);
if (DB::isError($db)) {
p2die($result->getMessage());
}
// テンプレートエンジン初期化
$_flexy_options = array(
'locale' => 'ja',
'charset' => 'cp932',
'compileDir' => $_conf['compile_dir'] . DIRECTORY_SEPARATOR . 'ic2',
'templateDir' => P2EX_LIB_DIR . '/ic2/templates',
'numberFormat' => '', // ",0,'.',','" と等価
);
$flexy = new HTML_Template_Flexy($_flexy_options);
// }}}
// {{{ データベース操作・ファイル削除
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'dropZero':
case 'dropAborn':
require_once P2EX_LIB_DIR . '/ic2/managedb.inc.php';
if ($_POST['action'] == 'dropZero') {
$where = $db->quoteIdentifier('rank') . ' = 0';
if (isset($_POST['dropZeroLimit'])) {
switch ($_POST['dropZeroSelectTime']) {
case '24hours': $expires = 86400; break;
case 'aday': $expires = 86400; break;
case 'aweek': $expires = 86400 * 7; break;
case 'amonth': $expires = 86400 * 31; break;
case 'ayear': $expires = 86400 * 365; break;
default: $expires = NULL;
}
if ($expires !== NULL) {
$operator = ($_POST['dropZeroSelectType'] == 'within') ? '>' : '<';
$where .= sprintf(' AND %s %s %d',
$db->quoteIdentifier('time'),
$operator,
time() - $expires);
}
}
$to_blacklist = !empty($_POST['dropZeroToBlackList']);
} else {
$where = $db->quoteIdentifier('rank') . ' < 0';
$to_blacklist = TRUE;
}
$sql = sprintf('SELECT %s FROM %s WHERE %s;',
$db->quoteIdentifier('id'),
$db->quoteIdentifier($ini['General']['table']),
$where);
$result = $db->getAll($sql, NULL, DB_FETCHMODE_ORDERED | DB_FETCHMODE_FLIPPED);
if (DB::isError($result)) {
$_info_msg_ht .= $result->getMessage();
break;
}
$target = $result[0];
$removed_files = manageDB_remove($target, $to_blacklist);
$flexy->setData('toBlackList', $to_blacklist);
break;
case 'clearThumb':
$thumb_dir2 = $ini['General']['cachedir'] . '/' . $ini['Thumb2']['name'];
$thumb_dir3 = $ini['General']['cachedir'] . '/' . $ini['Thumb3']['name'];
$result_files2 = P2Util::garbageCollection($thumb_dir2, -1, '', '', TRUE);
$result_files3 = P2Util::garbageCollection($thumb_dir3, -1, '', '', TRUE);
$removed_files = array_merge($result_files2['successed'], $result_files3['successed']);
$failed_files = array_merge($result_files2['failed'], $result_files3['failed']);
if (!empty($failed_files)) {
$_info_msg_ht .= '<p>以下のファイルが削除できませんでした。</p>';
$_info_msg_ht .= '<ul><li>';
$_info_msg_ht .= implode('</li><li>', array_map('htmlspecialchars', $failed_files));
$_info_msg_ht .= '</li></ul>';
}
break;
case 'clearCache':
$result = $db->query('DELETE FROM ' . $db->quoteIdentifier($ini['Cache']['table']));
if (DB::isError($result)) {
$_info_msg_ht .= $result->getMessage();
} else {
$_info_msg_ht .= "<p>テーブル {$ini['Cache']['table']} を空にしました。</p>";
}
$result_files = P2Util::garbageCollection($flexy->options['compileDir'], -1, '', '', TRUE);
$removed_files = $result_files['successed'];
if (!empty($result_files['failed'])) {
$_info_msg_ht .= '<p>以下のファイルが削除できませんでした。</p>';
$_info_msg_ht .= '<ul><li>';
$_info_msg_ht .= implode('</li><li>', array_map('htmlspecialchars', $result_files['failed']));
$_info_msg_ht .= '</li></ul>';
}
break;
case 'clearErrorLog':
$result = $db->query('DELETE FROM ' . $db->quoteIdentifier($ini['General']['error_table']));
if (DB::isError($result)) {
$_info_msg_ht .= $result->getMessage();
} else {
$_info_msg_ht .= '<p>エラーログを消去しました。</p>';
}
break;
case 'clearBlackList':
$result = $db->query('DELETE FROM ' . $db->quoteIdentifier($ini['General']['blacklist_table']));
if (DB::isError($result)) {
$_info_msg_ht .= $result->getMessage();
} else {
$_info_msg_ht .= '<p>ブラックリストを消去しました。</p>';
}
break;
case 'vacuumDB':
if ($db->dsn['phptype'] == 'sqlite') {
$db_file = $db->dsn['database'];
$size_b = filesize($db_file);
$result = $db->query('VACUUM');
if (DB::isError($result)) {
$_info_msg_ht .= $result->getMessage();
} else {
clearstatcache();
$size_a = filesize($db_file);
$_info_msg_ht .= sprintf('<p>VACUUM実行、ファイルサイズ: %s → %s (-%s)',
number_format($size_b),
number_format($size_a),
number_format($size_b - $size_a));
}
}
break;
default:
$_info_msg_ht .= '<p>不正なクエリ: ' . htmlspecialchars($_POST['action'], ENT_QUOTES) . '</p>';
}
if (isset($removed_files)) {
$flexy->setData('removedFiles', $removed_files);
}
}
// }}}
// {{{ 出力
$flexy->setData('skin', $skin_en);
$flexy->setData('php_self', $_SERVER['SCRIPT_NAME']);
$flexy->setData('info_msg', $_info_msg_ht);
if ($db->dsn['phptype'] == 'sqlite') {
$flexy->setData('isSQLite', TRUE);
}
$flexy->setData('pc', !$_conf['ktai']);
$flexy->setData('iphone', $_conf['iphone']);
$flexy->setData('doctype', $_conf['doctype']);
$flexy->setData('extra_headers', $_conf['extra_headers_ht']);
$flexy->setData('extra_headers_x', $_conf['extra_headers_xht']);
P2Util::header_nocache();
$flexy->compile('ic2mng.tpl.html');
$flexy->output();
// }}}
/*
* 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: