-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage-movies.php
290 lines (274 loc) · 15.5 KB
/
manage-movies.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/** 初始化组件 */
Typecho_Widget::widget('Widget_Init');
/** 注册一个初始化插件 */
Typecho_Plugin::factory('admin/common.php')->begin();
Typecho_Widget::widget('Widget_Options')->to($options);
Typecho_Widget::widget('Widget_User')->to($user);
Typecho_Widget::widget('Widget_Security')->to($security);
Typecho_Widget::widget('Widget_Menu')->to($menu);
/** 初始化上下文 */
$request = $options->request;
$response = $options->response;
$db = Typecho_Db::get(); // 确保数据库对象的初始化
include 'header.php';
include 'menu.php';
?>
<style>
.year, .douban-id {
font-size: .92857em;
color: #999;
}
input[type="date"] {
background: #FFF;
border: 1px solid #D9D9D6;
padding: 7px;
border-radius: 2px;
box-sizing: border-box;
}
.typecho-option label.typecho-label {
margin: .25em 0;
}
</style>
<div class="main">
<div class="body container">
<?php include 'page-title.php'; ?>
<div class="row typecho-page-main manage-metas">
<div class="col-mb-12">
<ul class="typecho-option-tabs clearfix">
<li class="current"><a href="<?php $options->adminUrl('extending.php?panel=ContentManager/manage-movies.php'); ?>"><?php _e('电影管理'); ?></a></li>
<li><a href="https://shawnzeng.com/index.php/archives/3/" title="查看电影管理使用帮助" target="_blank"><?php _e('帮助'); ?></a></li>
</ul>
</div>
<div class="col-mb-12 col-tb-9" role="main">
<?php
$prefix = $db->getPrefix();
$movies = $db->fetchAll($db->select()->from($prefix . 'movies')->order($prefix . 'movies.id', Typecho_Db::SORT_ASC));
?>
<form method="post" name="manage_movies" class="operate-form">
<div class="typecho-list-operate clearfix">
<div class="operate">
<label><i class="sr-only"><?php _e('全选'); ?></i><input type="checkbox" class="typecho-table-select-all" /></label>
<div class="btn-group btn-drop">
<button class="btn dropdown-toggle btn-s" type="button"><i class="sr-only"><?php _e('操作'); ?></i><?php _e('选中项'); ?> <i class="i-caret-down"></i></button>
<ul class="dropdown-menu">
<li><a lang="<?php _e('你确定要删除这些电影吗'); ?>" href="<?php $security->index('/action/movies-edit?content-type=movie&do=delete') ?>" ><?php _e('删除'); ?></a></li>
</ul>
</div>
</div>
</div>
<div class="typecho-table-wrap" style="padding: 20px 10px;">
<table class="typecho-list-table">
<colgroup>
<col width="20">
<col width="10%">
<col width="15%">
<col width="10%">
<col width="15%">
<col width="">
<col width="10%">
<col width="8%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th></th>
<th><?php _e('海报'); ?></th>
<th><?php _e('电影名'); ?></th>
<th><?php _e('id|豆瓣id'); ?></th>
<th><?php _e('导演'); ?></th>
<th><?php _e('演员'); ?></th>
<th><?php _e('分类'); ?></th>
<th><?php _e('评分'); ?></th>
<th><?php _e('操作'); ?></th>
</tr>
</thead>
<tbody>
<?php if (!empty($movies)): $alt = 0;?>
<?php foreach ($movies as $movie): ?>
<tr id="movie-<?php echo $movie['id']; ?>">
<td><input type="checkbox" value="<?php echo $movie['id']; ?>" name="id[]"/></td>
<td><?php if ($movie['image_url']) { ?>
<img src="<?php echo $movie['image_url']; ?>" referrerpolicy="no-referrer" style="max-width: 50px; max-height: 80px;"/>
<?php } ?></td>
<td>
<?php echo $movie['name'];
if ($movie['year']) {
echo '<br><span class="year">' . $movie['year'] . '</span>';
} ?>
</td>
<td>
<?php echo $movie['id'] ;
if ($movie['douban_id']) {
echo '<br><span class="douban-id">' . $movie['douban_id'] . '</span>';
}
?>
</td>
<td><?php echo $movie['directors']; ?></td>
<td><?php echo $movie['actors']; ?></td>
<td><?php echo $movie['genres']; ?></td>
<td><?php echo $movie['rating']; ?></td>
<td>
<a href="<?php echo $request->makeUriByRequest('id=' . $movie['id']); ?>"><?php _e('编辑'); ?></a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="8"><h6 class="typecho-list-table-title"><?php _e('没有任何电影'); ?></h6></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</form>
</div>
<div class="col-mb-12 col-tb-3" role="form">
<div class="typecho-mini-panel">
<form method="post" enctype="multipart/form-data" action="<?php $security->index('/action/movies-edit'); ?>">
<input type="hidden" name="content-type" id="content-type" value="movie">
<input type="hidden" name="id" id="movie-id">
<input type="hidden" name="do" id="action" value="insert">
<ul class="typecho-option">
<li>
<label for="douban_id" class="typecho-label"><?php _e('豆瓣ID'); ?></label>
<input type="text" id="douban_id" name="douban_id" class="text" />
<button type="button" class="btn" onclick="fetchDoubanInfo()">获取电影信息</button> <!-- 新增按钮 -->
</li>
<li>
<label for="name" class="typecho-label"><?php _e('电影名*'); ?></label>
<input type="text" id="name" name="name" class="text" required />
</li>
<li>
<label for="year" class="typecho-label"><?php _e('年份'); ?></label>
<input type="text" id="year" name="year" class="text" />
</li>
<li>
<label for="directors" class="typecho-label"><?php _e('导演*'); ?></label>
<input type="text" id="directors" name="directors" class="text" required />
</li>
<li>
<label for="actors" class="typecho-label"><?php _e('演员*'); ?></label>
<input type="text" id="actors" name="actors" class="text" required />
</li>
<li>
<label for="genres" class="typecho-label"><?php _e('分类*'); ?></label>
<input type="text" id="genres" name="genres" class="text" required />
</li>
<li>
<label for="image_url" class="typecho-label"><?php _e('海报*'); ?></label>
<input type="text" id="image_url" name="image_url" class="text" required />
<input type="file" name="image_file" id="image_file" accept="image/*" onchange="uploadImage(this)" /> <!-- 添加 onchange 事件 -->
<img id="preview-image" src="" alt="Image Preview" referrerpolicy="no-referrer" style="width: 100px; display: none;">
</li>
<li>
<label for="watch_date" class="typecho-label"><?php _e('观影日期*'); ?></label>
<input type="date" name="watch_date" id="watch_date" value="<?php echo date('Y-m-d'); ?>" required>
</li>
<li>
<label for="rating" class="typecho-label"><?php _e('评分*'); ?></label>
<input type="number" step="0.1" id="rating" name="rating" class="text" style="background: #FFF;border: 1px solid #D9D9D6;padding: 7px;border-radius: 2px;box-sizing: border-box;" required />
</li>
<li>
<label for="description" class="typecho-label"><?php _e('简介'); ?></label>
<textarea name="description" id="description"></textarea>
</li>
</ul>
<button type="submit" class="btn primary"><?php _e('保存'); ?></button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
include 'copyright.php';
include 'common-js.php';
?>
<script type="text/javascript">
(function () {
$(document).ready(function () {
$('.typecho-list-table').tableSelectable({
checkEl: 'input[type=checkbox]',
rowEl: 'tr',
selectAllEl: '.typecho-table-select-all',
actionEl: '.dropdown-menu a'
});
$('.btn-drop').dropdownMenu({
btnEl: '.dropdown-toggle',
menuEl: '.dropdown-menu'
});
<?php if (isset($request->id)) {
$movie = $db->fetchRow($db->select()->from($prefix . 'movies')->where('id = ?', $request->id));
?>
$('.typecho-mini-panel').effect('highlight', '#AACB36');
document.getElementById('movie-id').value = '<?php echo $movie["id"] ?>';
document.getElementById('action').value = 'update';
document.getElementById('name').value = '<?php echo htmlspecialchars($movie["name"]); ?>';
document.getElementById('year').value = '<?php echo $movie["year"] ?>';
document.getElementById('directors').value = '<?php echo htmlspecialchars($movie["directors"]); ?>';
document.getElementById('actors').value = '<?php echo htmlspecialchars($movie["actors"]); ?>';
document.getElementById('genres').value = '<?php echo htmlspecialchars($movie["genres"]); ?>';
document.getElementById('image_url').value = '<?php echo htmlspecialchars($movie["image_url"]); ?>';
document.getElementById('preview-image').src = '<?php echo htmlspecialchars($movie["image_url"]); ?>';
document.getElementById('preview-image').style.display = 'block';
document.getElementById('douban_id').value = '<?php echo $movie["douban_id"] ?>';
document.getElementById('watch_date').value = '<?php echo $movie["watch_date"] ?>';
document.getElementById('rating').value = '<?php echo $movie["rating"] ?>';
document.getElementById('description').value = `<?php echo htmlspecialchars($movie["description"]); ?>`;
<?php } ?>
});
})();
function uploadImage(input) {
var formData = new FormData();
formData.append('image_file', input.files[0]);
fetch('<?php echo $security->getIndex('action/movies-edit?content-type=image&do=upload'); ?>', { // 使用新的上传路径
method: 'POST',
body: formData
}).then(response => response.text()).then(data => {
if (data.startsWith('http')) { // 检查返回的是否是URL
document.getElementById('image_url').value = data.trim();
document.getElementById('preview-image').src = data.trim();
document.getElementById('preview-image').style.display = 'block';
} else {
console.error('Error uploading image:', data);
}
}).catch(error => {
console.error('Error uploading image:', error);
});
}
function fetchDoubanInfo() {
var doubanId = document.getElementById('douban_id').value;
if (!doubanId) {
alert('请填写豆瓣ID');
return;
}
// 获取插件目录路径
var pluginUrl = '<?php echo Typecho_Common::url('ContentManager/fetch-douban-info.php', Helper::options()->pluginUrl); ?>';
pluginUrl += '?info_type=movie&movie_id=' + doubanId;
fetch(pluginUrl)
.then(response => response.json())
.then(data => {
if (data.error) {
alert('获取电影信息失败: ' + data.error);
} else {
document.getElementById('name').value = data.title || '';
document.getElementById('year').value = data.year || '';
document.getElementById('directors').value = data.directors.map(d => d.name).join(' / ') || '';
document.getElementById('actors').value = data.casts.map(c => c.name).join(' / ') || '';
document.getElementById('genres').value = data.genres.join(' / ') || '';
document.getElementById('image_url').value = data.images.large || '';
document.getElementById('rating').value = data.rating.average || '';
document.getElementById('description').value = data.summary || '';
// 更新图片预览
document.getElementById('preview-image').src = data.images.large || '';
document.getElementById('preview-image').style.display = data.images.large ? 'block' : 'none';
}
})
.catch(error => {
console.error('Error fetching movie info:', error);
alert('获取电影信息失败');
});
}
</script>
<?php include 'footer.php'; ?>