-
Notifications
You must be signed in to change notification settings - Fork 8
/
Manage.php
361 lines (313 loc) · 12.3 KB
/
Manage.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
use Widget\Contents\Post\Edit;
use Typecho\Widget\Request;
use Typecho\Widget\Response;
use Typecho\Request as HttpRequest;
use Typecho\Response as HttpResponse;
use TypechoPlugin\Dynamics\Plugin as DynamicsPlugin;
use Utils\Helper;
include 'header.php';
include 'menu.php';
$post = new Edit(
new Request(
HttpRequest::getInstance()
), new Response(
HttpRequest::getInstance(),
HttpResponse::getInstance()
)
);
?>
<style type="text/css">
.dynamic-row {
background-color: #fff;
word-wrap: break-word;
word-break: break-all;
}
.dynamic-row.row {
margin-left: 0 !important;
margin-right: 0 !important;
}
.dynamic-left {
padding-left: 0 !important;
padding-right: 0 !important;
/*border-right: 6px #e4dad1 solid;*/
border-right: 8px rgba(140, 162, 157, 0.15) solid;
min-height: 400px !important;
}
.dynamic-add {
border-bottom: 1px #e4dad1 solid;
height: 40px;
line-height: 40px;
text-align: center;
display: block;
}
.dynamic-list-item {
/*border-top: 1px #e4dad1 solid; */
border-bottom: 1px #e4dad1 solid;
padding: 10px 10px 10px 10px;
font-size: 14px;
background-color: #fff;
cursor: pointer;
}
.dynamic-list-item:hover {
background-color: #F6F6F3;
}
.dynamic-list-item.active {
background-color: rgba(94, 169, 169, 0.17);
}
.dynamic-list-item div.title {
}
.dynamic-list-item div.subtitle {
font-size: 10px;
margin-top: 3px;
color: #827C7C;
}
.dynamic-list-item div.subtitle .author {
float: right;
}
.dynamic-left .dynamic-more-load {
cursor: pointer;
}
.dynamic-left .dynamic-more-load .loading {
display: none;
}
.dynamic-left .dynamic-more-no {
display: none;
}
.dynamic-left .dynamic-more-load, .dynamic-left .dynamic-more-no {
text-align: center;
padding: 10px 10px;
}
.dynamic-right {
padding: 10px 10px 10px 10px;
/*border-left: 8px #e4dad1 solid;*/
border-left: 8px rgba(140, 162, 157, 0.15) solid;
margin-left: -8px;
min-height: 600px !important;
}
.dynamic-right .title {
display: none;
}
.dynamic-right .save {
display: none;
}
#dynamic-btn-box {
float: right;
margin-top: 20px;
}
</style>
<div class="main">
<div class="body container">
<?php include 'page-title.php'; ?>
<div class="row typecho-page-main" role="main">
<div class="col-mb-12">
<ul class="typecho-option-tabs fix-tabs clearfix">
<li class="current"><a href="#">我的动态</a></li>
<li><a href="<?php Helper::options()->index(DynamicsPlugin::DEFAULT_ROUTE); ?>"
target="_blank">动态首页</a>
</li>
<li>
<a href="<?php Helper::options()->adminUrl('extending.php?panel=Dynamics%2FThemes.php'); ?>">主题设置</a>
</li>
<li>
<a href="<?php Helper::options()->adminUrl('options-plugin.php?config=Dynamics'); ?>">插件设置</a>
</li>
</ul>
</div>
<div class="col-mb-12 typecho-list">
<div class="dynamic-row row">
<div class="col-mb-4 dynamic-left">
<div class="dynamic-list">
<div class="dynamic-add">我的动态</div>
<div class="dynamic-body"></div>
<div class="dynamic-more-load" href="javascript:void(0)">
<span>加载更多</span>
<span class="loading">中...</span>
</div>
<div class="dynamic-more-no">没有更多动态了</div>
</div>
</div>
<div class="col-mb-8 dynamic-right">
<p>
<label for="text" class="sr-only"><?php _e('文章内容'); ?></label>
<textarea placeholder="请输入正文" style="height: <?php $options->editorSize(); ?>px"
autocomplete="off" id="text" name="text" class="w-100 mono"></textarea>
</p>
</div>
</div>
<div id="dynamic-btn-box">
<button type="submit" name="do" value="adds" class="adds btn">新建动态</button>
<button type="submit" name="do" value="delete" class="delete btn">删除此动态</button>
<button type="submit" name="do" value="publish" class="save btn primary" id="btn-submit">保存动态
</button>
</div>
</div>
</div>
</div>
</div>
<?php
include 'copyright.php';
include 'common-js.php';
include 'table-js.php';
include 'editor-js.php';
?>
<script>
$(document).ready(function () {
function layoutOf(data) {
return '<div class="dynamic-list-item" data-id="' + data.did + '">' +
'<div class="title">' + data.title + '<a href="' + data.url + '" target="_blank"><i class="i-exlink"></i></a></div>' +
'<div class="subtitle">' +
'<span class="desc">' + data.desc + '</span>' +
'<span class="author">' + data.nickname + '</span>' +
'</div>' +
'</div>';
}
function message(notice, noticeType = 'error') {
let head = $('.typecho-head-nav'),
p = $('<div class="message popup ' + noticeType + '">'
+ '<ul><li>' + notice + '</li></ul></div>'), offset = 0;
if (head.length > 0) {
p.insertAfter(head);
offset = head.outerHeight();
} else {
p.prependTo(document.body);
}
function checkScroll() {
if ($(window).scrollTop() >= offset) {
p.css({
'position': 'fixed',
'top': 0
});
} else {
p.css({
'position': 'absolute',
'top': offset
});
}
}
$(window).scroll(function () {
checkScroll();
});
checkScroll();
p.slideDown(function () {
let t = $(this), color = '#C6D880';
if (t.hasClass('error')) {
color = '#FBC2C4';
} else if (t.hasClass('notice')) {
color = '#FFD324';
}
t.effect('highlight', {color: color})
.delay(5000).fadeOut(function () {
$(this).remove();
});
});
}
let lastDid = 0, selectId = 0, dynData = [],
actionUrl = '<?php Helper::options()->index("action/dynamics?do=");?>';
function loadDynamics() {
$.get(actionUrl + 'list', {
lastDid: lastDid
}, function (data) {
if (data.code) {
let len = data.data.length;
if (len === 0) {
$('.dynamic-left .dynamic-more-load').hide();
$('.dynamic-left .dynamic-more-no').show();
message('没有动态噢', 'notice');
} else {
lastDid = data.data[len - 1].did;
let temp = '';
for (let i = 0; i < len; i++) {
dynData['key_' + data.data[i].did] = data.data[i];
temp += layoutOf(data.data[i]);
}
$('.dynamic-list .dynamic-body').append(temp);
$('.dynamic-more-load .loading').hide();
if (!selectId) {
$('.dynamic-list .dynamic-list-item[data-id=' + data.data[0].did + ']').click();
$('.wmd-edittab a[href="#wmd-preview"]').click();
}
}
} else {
message(data.msg);
}
});
}
let textarea = $('#text');
$(document).on('click', '.dynamic-list .dynamic-list-item', function () {
$('.dynamic-list .dynamic-list-item').each(function (k, ele) {
$(ele).removeClass('active');
});
$(this).addClass('active');
selectId = $(this).attr("data-id");
let dyn = dynData['key_' + $(this).attr("data-id")];
textarea.val(dyn.text);
textarea[0].dispatchEvent(new Event('input'));
});
$(document).on('click', '#dynamic-btn-box .adds', function () {
$.get(actionUrl + 'add', {}, function (data) {
if (data.code) {
message('新增成功', 'success');
dynData['key_' + data.data.did] = data.data;
let temp = layoutOf(data.data);
temp = $(temp);
$('.dynamic-list .dynamic-body').prepend(temp);
temp.click();
$('.wmd-edittab a[href="#wmd-editarea"]').click();
$('.dynamic-right .title').focus();
} else {
message(data.msg);
}
})
});
$(document).on('click', '.dynamic-list .dynamic-more-load', function () {
$('.dynamic-more-load .loading').show();
loadDynamics();
});
$(document).on('click', '#dynamic-btn-box .save', function () {
if (selectId) {
$.get(actionUrl + 'save', {
did: selectId,
title: $('.dynamic-right .title').val(),
text: $('#text').val(),
}, function (data) {
if (data.code) {
message('保存成功', 'success');
dynData['key_' + data.data.did] = data.data;
let list_item = $('.dynamic-body .dynamic-list-item[data-id="' + data.data.did + '"]');
list_item.find('.subtitle .desc').html(data.data.desc);
} else {
message(data.msg);
}
})
}
});
$(document).on('click', '#dynamic-btn-box .delete', function () {
if (confirm('确定删除该动态')) {
if (selectId) {
$.get(actionUrl + 'remove', {
did: selectId
}, function (data) {
if (data.code) {
message('删除成功', 'success');
delete dynData['key_' + selectId];
let list_item = $('.dynamic-body .dynamic-list-item[data-id="' + selectId + '"]');
if (list_item.prev().length !== 0) {
list_item.prev().click();
} else if (list_item.next().length !== 0) {
list_item.next().click();
} else {
$('.dynamic-right').hide();
}
list_item.remove();
} else {
message(data.msg);
}
});
}
}
});
loadDynamics();
});
</script>
<?php include 'footer.php'; ?>