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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
<?php # $Id: entries.inc.php 540 2005-10-06 09:36:53Z garvinhicking $ # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team) # All rights reserved. See LICENSE file for licensing details
if (IN_serendipity !== true) { die ("Don't hack!"); }
if (!serendipity_checkPermission('adminEntries')) { return; }
$sort_order = array('timestamp' => DATE, 'isdraft' => PUBLISH . '/' . DRAFT, 'a.realname' => AUTHOR, 'category_name' => CATEGORY, 'last_modified' => LAST_UPDATED, 'title' => TITLE); $per_page = array('12', '16', '50', '100');
// A little helper we don't want in _functions.inc.php function serendipity_drawList() { global $serendipity, $sort_order, $per_page;
$filter_import = array('author', 'category', 'isdraft'); $sort_import = array('perPage', 'ordermode', 'order'); foreach($filter_import AS $f_import) { serendipity_restoreVar($serendipity['COOKIE']['entrylist_filter_' . $f_import], $serendipity['GET']['filter'][$f_import]); serendipity_JSsetCookie('entrylist_filter_' . $f_import, $serendipity['GET']['filter'][$f_import]); }
foreach($sort_import AS $s_import) { serendipity_restoreVar($serendipity['COOKIE']['entrylist_sort_' . $s_import], $serendipity['GET']['sort'][$s_import]); serendipity_JSsetCookie('entrylist_sort_' . $s_import, $serendipity['GET']['sort'][$s_import]); }
$perPage = (!empty($serendipity['GET']['sort']['perPage']) ? $serendipity['GET']['sort']['perPage'] : $per_page[0]); $page = (int)$serendipity['GET']['page']; $offSet = $perPage*$page;
if (empty($serendipity['GET']['sort']['ordermode']) || $serendipity['GET']['sort']['ordermode'] != 'ASC') { $serendipity['GET']['sort']['ordermode'] = 'DESC'; }
if (!empty($serendipity['GET']['sort']['order']) && !empty($sort_order[$serendipity['GET']['sort']['order']])) { $orderby = serendipity_db_escape_string($serendipity['GET']['sort']['order'] . ' ' . $serendipity['GET']['sort']['ordermode']); } else { $orderby = 'timestamp ' . serendipity_db_escape_string($serendipity['GET']['sort']['ordermode']); }
$filter = array();
if (!empty($serendipity['GET']['filter']['author'])) { $filter[] = "e.authorid = '" . serendipity_db_escape_string($serendipity['GET']['filter']['author']) . "'"; }
if (!empty($serendipity['GET']['filter']['category'])) { $filter[] = "ec.categoryid = '" . serendipity_db_escape_string($serendipity['GET']['filter']['category']) . "'"; }
if (!empty($serendipity['GET']['filter']['isdraft'])) { if ($serendipity['GET']['filter']['isdraft'] == 'draft') { $filter[] = "e.isdraft = 'true'"; } elseif ($serendipity['GET']['filter']['isdraft'] == 'publish') { $filter[] = "e.isdraft = 'false'"; } }
if (!empty($serendipity['GET']['filter']['body'])) { if ($serendipity['dbType'] == 'mysql') { $filter[] = "MATCH (title,body,extended) AGAINST ('" . serendipity_db_escape_string($serendipity['GET']['filter']['body']) . "')"; $full = true; } }
$filter_sql = implode(' AND ', $filter);
// Fetch the entries $entries = serendipity_fetchEntries( false, false, serendipity_db_limit( $offSet, $perPage ), true, false, $orderby, $filter_sql ); ?> <form action="?" method="get"> <div class="serendipity_admin_list"> <input type="hidden" name="serendipity[action]" value="admin" /> <input type="hidden" name="serendipity[adminModule]" value="entries" /> <input type="hidden" name="serendipity[adminAction]" value="editSelect" /> <table width="100%" class="serendipity_admin_filters"> <tr> <td class="serendipity_admin_filters_headline" colspan="6"><strong><?php echo FILTERS ?></strong> - <?php echo FIND_ENTRIES ?></td> </tr> <tr> <td valign="top" width="80"><?php echo AUTHOR ?></td> <td valign="top"> <select name="serendipity[filter][author]"> <option value="">--</option> <?php $users = serendipity_fetchUsers(); if (is_array($users)) { foreach ($users AS $user) { echo '<option value="' . $user['authorid'] . '" ' . (isset($serendipity['GET']['filter']['author']) && $serendipity['GET']['filter']['author'] == $user['authorid'] ? 'selected="selected"' : '') . '>' . $user['realname'] . '</option>' . "\n"; } } ?> </select> <select name="serendipity[filter][isdraft]"> <option value="all"><?php echo COMMENTS_FILTER_ALL; ?></option> <option value="draft" <?php echo (isset($serendipity['GET']['filter']['isdraft']) && $serendipity['GET']['filter']['isdraft'] == 'draft' ? 'selected="selected"' : ''); ?>><?php echo DRAFT; ?></option> <option value="publish" <?php echo (isset($serendipity['GET']['filter']['isdraft']) && $serendipity['GET']['filter']['isdraft'] == 'publish' ? 'selected="selected"' : ''); ?>><?php echo PUBLISH; ?></option> </select> </td> <td valign="top" width="80"><?php echo CATEGORY ?></td> <td valign="top"> <select name="serendipity[filter][category]"> <option value="">--</option> <?php $categories = serendipity_fetchCategories(); $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED); foreach ( $categories as $cat ) { echo '<option value="'. $cat['categoryid'] .'"'. ($serendipity['GET']['filter']['category'] == $cat['categoryid'] ? ' selected="selected"' : '') .'>'. str_repeat(' ', $cat['depth']) . $cat['category_name'] .'</option>' . "\n"; } ?> </select> </td> <td valign="top" width="80"><?php echo CONTENT ?></td> <td valign="top"><input size="10" type="text" name="serendipity[filter][body]" value="<?php echo (isset($serendipity['GET']['filter']['body']) ? htmlspecialchars($serendipity['GET']['filter']['body']) : '') ?>" /></td> </tr> <tr> <td class="serendipity_admin_filters_headline" colspan="6"><strong><?php echo SORT_ORDER ?></strong></td> </tr> <tr> <td> <?php echo SORT_BY ?> </td> <td> <select name="serendipity[sort][order]"> <?php foreach($sort_order as $so_key => $so_val) { echo '<option value="' . $so_key . '" ' . (isset($serendipity['GET']['sort']['order']) && $serendipity['GET']['sort']['order'] == $so_key ? 'selected="selected"': '') . '>' . $so_val . '</option>' . "\n"; } ?> </select> </td> <td><?php echo SORT_ORDER ?></td> <td> <select name="serendipity[sort][ordermode]"> <option value="DESC" <?php echo (isset($serendipity['GET']['sort']['ordermode']) && $serendipity['GET']['sort']['ordermode'] == 'DESC' ? 'selected="selected"' : '') ?>><?php echo SORT_ORDER_DESC ?></option> <option value="ASC" <?php echo (isset($serendipity['GET']['sort']['ordermode']) && $serendipity['GET']['sort']['ordermode'] == 'ASC' ? 'selected="selected"' : '') ?>><?php echo SORT_ORDER_ASC ?></option> </select> </td> <td><?php echo ENTRIES_PER_PAGE ?></td> <td> <select name="serendipity[sort][perPage]"> <?php foreach($per_page AS $per_page_nr) { echo '<option value="' . $per_page_nr . '" ' . (isset($serendipity['GET']['sort']['perPage']) && $serendipity['GET']['sort']['perPage'] == $per_page_nr ? 'selected="selected"' : '') . '>' . $per_page_nr . '</option>' . "\n"; }
?> </select> </td> </tr> <tr> <td align="right" colspan="6"><input type="submit" name="go" value="<?php echo GO ?>" class="serendipityPrettyButton" /></td> </tr> </table> <table class="serendipity_admin_list" cellpadding="5" width="100%"> <?php if (is_array($entries)) { $count = count($entries); $qString = '?serendipity[adminModule]=entries&serendipity[adminAction]=editSelect'; foreach ((array)$serendipity['GET']['sort'] as $k => $v) { $qString .= '&serendipity[sort]['. $k .']='. $v; } foreach ((array)$serendipity['GET']['filter'] as $k => $v) { $qString .= '&serendipity[filter]['. $k .']='. $v; } $linkPrevious = $qString . '&serendipity[page]=' . ($page-1); $linkNext = $qString . '&serendipity[page]=' . ($page+1); ?> <tr> <td> <?php if ($offSet > 0) { ?> <a href="<?php echo $linkPrevious ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/previous.png') ?>" /><?php echo PREVIOUS ?></a> <?php } ?> </td> <td align="right"> <?php if ($count == $perPage) { ?> <a href="<?php echo $linkNext ?>" class="serendipityIconLinkRight"><?php echo NEXT ?><img src="<?php echo serendipity_getTemplateFile('admin/img/next.png') ?>" /></a> <?php } ?> </td> </tr> </table> <?php // Print the entries $rows = 0; foreach ( $entries as $entry ) { $rows++; // Find out if the entry has been modified later than 30 minutes after creation if ($entry['timestamp'] <= ($entry['last_modified'] - 60*30)) { $lm = '<a href="#" title="' . LAST_UPDATED . ': ' . serendipity_formatTime(DATE_FORMAT_SHORT, $entry['last_modified']) . '" onclick="alert(this.title)"><img src="'. serendipity_getTemplateFile('admin/img/clock.png') .'" alt="*" style="border: 0px none ; vertical-align: bottom;" /></a>'; } else { $lm = ''; }
if (!$serendipity['showFutureEntries'] && $entry['timestamp'] >= serendipity_serverOffsetHour()) { $entry_pre = '<a href="#" title="' . ENTRY_PUBLISHED_FUTURE . '" onclick="alert(this.title)"><img src="'. serendipity_getTemplateFile('admin/img/clock_future.png') .'" alt="*" style="border: 0px none ; vertical-align: bottom;" /></a> '; } else { $entry_pre = ''; }
if (serendipity_db_bool($entry['isdraft'])) { $entry_pre .= ' ' . DRAFT . ': '; } ?> <div class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo ($rows % 2 ? 'even' : 'uneven'); ?>"> <table width="100%" cellspacing="0" cellpadding="3"> <tr> <td> <strong><?php echo $entry_pre; ?><a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=<?php echo $entry['id']; ?>" title="#<?php echo $entry['id']; ?>"><?php echo serendipity_truncateString($entry['title'],50) ?></a></strong> </td> <td align="right"> <?php echo serendipity_formatTime(DATE_FORMAT_SHORT, $entry['timestamp']) . ' ' .$lm; ?> </td> </tr> <tr> <td> <?php echo POSTED_BY . ' ' . $entry['author']; if (count($entry['categories'])) { echo ' ' . IN . ' '; $cats = array(); foreach ($entry['categories'] as $cat) { $cats[] = '<a href="' . $serendipity['serendipityHTTPPath'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'categories/' . $cat['categoryid'] . '_' . serendipity_makeFilename($cat['category_name']) . '">' . $cat['category_name'] . '</a>'; } echo implode(', ', $cats); } ?>
</td> <td align="right"> <a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=<?php echo $entry['id']; ?>" title="<?php echo EDIT . ' #' . $entry['id']; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png'); ?>" alt="<?php echo EDIT; ?>" /><?php echo EDIT ?></a> <a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=delete&serendipity[id]=<?php echo $entry['id']; ?>" title="<?php echo DELETE . ' #' . $entry['id']; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/delete.png'); ?>" alt="<?php echo DELETE; ?>" /><?php echo DELETE ?></a> </td> </tr> </table> </div> <?php } // end entries output ?>
<table class="serendipity_admin_list" cellpadding="5" width="100%"> <tr> <td> <?php if ($offSet > 0) { ?> <a href="<?php echo $linkPrevious ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/previous.png') ?>" /><?php echo PREVIOUS ?></a> <?php } ?> </td> <td align="right"> <?php if ($count == $perPage) { ?> <a href="<?php echo $linkNext ?>" class="serendipityIconLinkRight"><?php echo NEXT ?><img src="<?php echo serendipity_getTemplateFile('admin/img/next.png') ?>" /></a> <?php } ?> </td> </tr> </table>
<div class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo (($rows+1) % 2 ? 'even' : 'uneven'); ?>"> <table width="100%" cellspacing="0" cellpadding="3"> <tr> <td> <?php echo EDIT_ENTRY ?>: #<input type="text" size="3" name="serendipity[id]" /> <input type="submit" name="serendipity[editSubmit]" value="<?php echo GO ?>" class="serendipityPrettyButton" /> </td> </tr> </table> </div> <?php } else { // We've got nothing ?> <div align="center">- <?php echo NO_ENTRIES_TO_PRINT ?> -</div> <?php } ?> </div> </form> <?php } // End function serendipity_drawList()
if (!empty($serendipity['GET']['editSubmit'])) { $serendipity['GET']['adminAction'] = 'edit'; }
switch($serendipity['GET']['adminAction']) { case 'save': $entry = array( 'id' => $serendipity['POST']['id'], 'title' => $serendipity['POST']['title'], 'timestamp' => $serendipity['POST']['timestamp'], 'body' => $serendipity['POST']['body'], 'extended' => $serendipity['POST']['extended'], 'categories' => $serendipity['POST']['categories'], 'isdraft' => $serendipity['POST']['isdraft'], 'allow_comments' => $serendipity['POST']['allow_comments'], 'moderate_comments' => $serendipity['POST']['moderate_comments'], 'exflag' => (!empty($serendipity['POST']['extended']) ? true : false) );
if ($entry['allow_comments'] != 'true' && $entry['allow_comments'] !== true) { $entry['allow_comments'] = 'false'; }
if ($entry['moderate_comments'] != 'true' && $entry['moderate_comments'] !== true) { $entry['moderate_comments'] = 'false'; }
// Check if the user changed the timestamp. if (isset($serendipity['allowDateManipulation']) && $serendipity['allowDateManipulation'] && isset($serendipity['POST']['new_timestamp']) && $serendipity['POST']['new_timestamp'] != date(DATE_FORMAT_2, $serendipity['POST']['chk_timestamp'])) { // The user changed the timestamp, now set the DB-timestamp to the user's date $entry['timestamp'] = strtotime($serendipity['POST']['new_timestamp']);
if ($entry['timestamp'] == -1) { echo DATE_INVALID . '<br />'; // The date given by the user is not convertable. Reset the timestamp. $entry['timestamp'] = $serendipity['POST']['timestamp']; } }
// Save server timezone in database always, so substract the offset we added for display; otherwise it would be added time and again if (!empty($entry['timestamp'])) { $entry['timestamp'] = serendipity_serverOffsetHour($entry['timestamp'], true); }
// Save the entry, or just display a preview if ($serendipity['POST']['preview'] != 'true') { /* We don't need an iframe to save a draft */ if ( $serendipity['POST']['isdraft'] == 'true' ) { echo '<div class="serendipityAdminMsgSuccess">' . IFRAME_SAVE_DRAFT . '</div><br />'; serendipity_updertEntry($entry); } else { if ($serendipity['use_iframe']) { echo '<div class="serendipityAdminMsgSuccess">' . IFRAME_SAVE . '</div><br />'; serendipity_iframe_create('save', $entry); } else { serendipity_iframe($entry, 'save'); } } } else { // Only display the preview $serendipity['hidefooter'] = true; if (!is_numeric($entry['timestamp'])) { $entry['timestamp'] = time(); }
if (!isset($entry['trackbacks']) || !$entry['trackbacks']) { $entry['trackbacks'] = 0; }
if (!isset($entry['comments']) || !$entry['comments']) { $entry['comments'] = 0; }
if (!isset($entry['realname']) || !$entry['realname']) { if (!empty($serendipity['realname'])) { $entry['realname'] = $serendipity['realname']; } else { $entry['realname'] = $serendipity['serendipityUser']; } }
$categories = (array)$entry['categories']; $entry['categories'] = array(); foreach ($categories as $catid) { if ($catid == 0) { continue; } $entry['categories'][] = serendipity_fetchCategoryInfo($catid); }
if (count($entry['categories']) < 1) { unset($entry['categories']); }
if (isset($entry['id'])) { $serendipity['GET']['id'] = $entry['id']; } else { $serendipity['GET']['id'] = 1; }
if ($serendipity['use_iframe']) { echo '<div class="serendipityAdminMsgSuccess">' . IFRAME_PREVIEW . '</div><br />'; serendipity_iframe_create('preview', $entry); } else { serendipity_iframe($entry, 'preview'); } }
// serendipity_updertEntry sets this global variable to store the entry id. Couldn't pass this // by reference or as return value because it affects too many places inside our API and dependant // function calls. if (!empty($serendipity['lastSavedEntry'])) { $entry['id'] = $serendipity['lastSavedEntry']; }
include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php'; serendipity_printEntryForm( '?', array( 'serendipity[action]' => 'admin', 'serendipity[adminModule]' => 'entries', 'serendipity[adminAction]' => 'save', 'serendipity[timestamp]' => $entry['timestamp'] ),
$entry );
break;
case 'doDelete': serendipity_deleteEntry($serendipity['GET']['id']); printf(RIP_ENTRY, $serendipity['GET']['id']); echo '<br />';
case 'editSelect': serendipity_drawList(); break;
case 'delete': $newLoc = '?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=doDelete&serendipity[id]=' . $serendipity['GET']['id']; printf(DELETE_SURE, $serendipity['GET']['id']); ?> <br /> <br /> <div> <a href="<?php echo $_SERVER["HTTP_REFERER"]; ?>" class="serendipityPrettyButton"><?php echo NOT_REALLY; ?></a> <?php echo str_repeat(' ', 10); ?> <a href="<?php echo $newLoc; ?>" class="serendipityPrettyButton"><?php echo DUMP_IT; ?></a> </div> <?php break;
case 'edit': $entry = serendipity_fetchEntry('id', $serendipity['GET']['id'], 1, 1);
default: include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
serendipity_printEntryForm( '?', array( 'serendipity[action]' => 'admin', 'serendipity[adminModule]' => 'entries', 'serendipity[adminAction]' => 'save' ), (isset($entry) ? $entry : array()) ); } /* vim: set sts=4 ts=4 expandtab : */ ?>
|