-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharticle.php
991 lines (785 loc) · 23.3 KB
/
article.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
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
<?php
/**
* @package phpBB-WAP
* @简体中文:中文phpBB-WAP团队
* @license http://opensource.org/licenses/gpl-license.php
**/
/**
* 这是一款自由软件, 您可以在 Free Software Foundation 发布的
* GNU General Public License 的条款下重新发布或修改; 您可以
* 选择目前 version 2 这个版本(亦可以选择任何更新的版本,由
* 你喜欢)作为新的牌照.
**/
/**
* phpBB-WAP 文章系统
*/
define('IN_PHPBB', true);
define('ROOT_PATH', './');
require(ROOT_PATH . 'common.php');
$userdata = $session->start($user_ip, PAGE_ARTICLE);
init_userprefs($userdata);
function article_class_select($default_class, $article_class)
{
global $db;
$class_select = '<select name="class">';
foreach ($article_class as $key => $value)
{
$selected = ($key == $default_class) ? ' selected="selected"' : '';
$class_select .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
}
$class_select .= "</select>";
return $class_select;
}
$sql = 'SELECT ac_id, ac_name
FROM ' . ARTICLES_CLASS_TABLE . '
ORDER BY ac_sort ASC';
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询文章分类数据', E_USER_WARNING);
}
$article_class = array();
while ($row = $db->sql_fetchrow($result))
{
$article_class[$row['ac_id']] = $row['ac_name'];
$template->assign_block_vars('article_class', array(
'ARTICLE_CLASS' => $row['ac_name'],
'U_ARTICLE_CLASS' => append_sid('article.php?mode=cat&id=' . $row['ac_id']))
);
}
$mode = (isset($_GET['mode'])) ? $_GET['mode'] : '';
if ($mode == 'view')
{
if (!isset($_GET['id']))
{
trigger_error('请指定要查看的文章');
}
$article_id = intval($_GET['id']);
$sql = 'SELECT article_class, article_title, article_poster, article_time, article_views, article_approval, article_text
FROM ' . ARTICLES_TABLE . '
WHERE article_id = ' . $article_id;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询文章数据', E_USER_WARNING);
}
if ($row = $db->sql_fetchrow($result))
{
if (!$posterdata = get_userdata($row['article_poster']))
{
$poster = '热心网友';
}
else
{
$poster = '<a href="' . append_sid('ucp.php?mode=viewprofile&u=' . $posterdata['user_id']) . '">' . $posterdata['username'] . '</a>';
}
$article_text = str_replace("\n", '</p><p>', $row['article_text']);
}
else
{
trigger_error('您要查看的文章不存在');
}
if ($row['article_poster'] == $userdata['user_id'] || $userdata['user_level'] == ADMIN)
{
// 如果时间小于一天则不允许编辑
if (((time() - $row['article_time']) < 86400) || $userdata['user_level'] == ADMIN)
{
$template->assign_block_vars('is_poster', array(
'U_EDIT' => append_sid('article.php?mode=edit&id=' . $article_id),
'U_DELETE' => append_sid('article.php?mode=delete&id=' . $article_id))
);
}
if (!$row['article_approval'])
{
$template->assign_block_vars('approval', array());
}
}
else
{
if (!$row['article_approval'])
{
trigger_error('此文章还没有通过审核');
}
}
if ($row['article_approval'])
{
$new_view = $row['article_views'] + 1;
$sql = 'UPDATE ' . ARTICLES_TABLE . '
SET article_views = ' . $new_view . '
WHERE article_id = ' . $article_id;
if (!$db->sql_query($sql))
{
trigger_error('无法更新浏览次数', E_USER_WARNING);
}
}
$sql = 'SELECT article_id, article_title
FROM ' . ARTICLES_TABLE . '
WHERE article_id < ' . $article_id . '
ORDER BY article_id DESC
LIMIT 0, 1';
if (!$result = $db->sql_query($sql))
{
trigger_error('无法取得下一篇文章的数据', E_USER_WARNING);
}
if ($db->sql_numrows($result))
{
$previou_row = $db->sql_fetchrow($result);
$previou_article = '<a href="' . append_sid('article.php?mode=view&id=' . $previou_row['article_id']) . '">' . $previou_row['article_title'] . '</a>';
}
else
{
$previou_article = '没有了';
}
$sql = 'SELECT article_id, article_title
FROM ' . ARTICLES_TABLE . '
WHERE article_id > ' . $article_id . '
ORDER BY article_id ASC
LIMIT 0, 1';
if (!$result = $db->sql_query($sql))
{
trigger_error('无法取得下一篇文章的数据', E_USER_WARNING);
}
if ($db->sql_numrows($result))
{
$next_row = $db->sql_fetchrow($result);
$next_article = '<a href="' . append_sid('article.php?mode=view&id=' .$next_row['article_id']) . '">' . $next_row['article_title'] . '</a>';
}
else
{
$next_article = '没有了';
}
page_header($row['article_title'] . '_浏览文章');
$template->set_filenames(array(
'body' => 'article/article_view.tpl')
);
$template->assign_vars(array(
'ARTICLE_TITLE' => $row['article_title'],
'ARTICLE_POSTER' => $poster,
'ARTICLE_TIME' => create_date('Y年m月d日 H:i', $row['article_time'], $board_config['board_timezone']),
'ARTICLE_VIEWS' => $row['article_views'],
'ARTICLE_TEXT' => $article_text,
'ARTICLE_PREVIOU' => $previou_article,
'ARTICLE_NEXT' => $next_article,
'U_BACK' => append_sid('article.php'),
)
);
$template->pparse('body');
page_footer();
}
elseif ($mode == 'cat')
{
if (!isset($_GET['id']))
{
trigger_error('请指定分类');
}
if (!isset($article_class[$_GET['id']]))
{
trigger_error('分类不存在');
}
$cid = $_GET['id'];
$per = 10;
$start = get_pagination_start($per);
$sql = 'SELECT article_title, article_id, article_views, article_approval
FROM ' . ARTICLES_TABLE .'
WHERE article_class = ' . $cid . '
ORDER BY article_time DESC
LIMIT ' . $start . ', ' . $per;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询该分类的文章数据', E_USER_WARNING);
}
$i = 0;
$noin_number = 0;
while ($row = $db->sql_fetchrow($result))
{
if (!$row['article_approval'])
{
if ($row['article_poster'] == $userdata['user_id'] || $userdata['user_level'] == ADMIN)
{
$row_class = ( !($i % 2) ) ? 'row1' : 'row2';
$template->assign_block_vars('article_cat', array(
'NUMBER' => $i + $start + 1,
'ROW_CLASS' => $row_class,
'ARTICLE_TITLE' => $row['article_title'],
'U_ARTICLE' => append_sid('article.php?mode=view&id=' . $row['article_id']))
);
$i++;
}
else
{
$noin_number++;
}
}
else
{
$row_class = ( !($i % 2) ) ? 'row1' : 'row2';
$template->assign_block_vars('article_cat', array(
'NUMBER' => $i + $start + 1,
'ROW_CLASS' => $row_class,
'ARTICLE_TITLE' => $row['article_title'],
'U_ARTICLE' => append_sid('article.php?mode=view&id=' . $row['article_id']))
);
$i++;
}
}
$sql = 'SELECT COUNT(article_id) AS total
FROM ' . ARTICLES_TABLE .'
WHERE article_class = ' . $cid;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询该分类的文章数据', E_USER_WARNING);
}
$row = $db->sql_fetchrow($result);
$total_article = (($row['total'] - $noin_number) < 0) ? 0 : ($row['total'] - $noin_number);
if (!$total_article)
{
$template->assign_block_vars('not_article', array());
}
page_header($article_class[$cid] . '_文章分类');
$template->set_filenames(array(
'body' => 'article/article_cat.tpl')
);
$template->assign_vars(array(
'CAT_TITLE' => $article_class[$cid],
'U_BACK' => append_sid('article.php'),
'U_NEW_ARTICLE' => append_sid('article.php?mode=post'),
'PAGINATION' => generate_pagination("article.php?mode=cat&id=$cid", $total_article, $per, $start)
)
);
$template->pparse('body');
page_footer();
}
elseif ($mode == 'edit')
{
if (!$userdata['session_logged_in'])
{
trigger_error('请先登录');
}
if (!isset($_GET['id']))
{
trigger_error('您没有选中任何文章');
}
$edit_id = intval($_GET['id']);
$sql = 'SELECT article_poster, article_time, article_class, article_title, article_text
FROM ' . ARTICLES_TABLE . '
WHERE article_id = ' . $edit_id;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法获取要修改的文章信息', E_USER_WARNING);
}
if (!$row = $db->sql_fetchrow($result))
{
trigger_error('没有这篇文章');
}
if ($userdata['user_level'] != ADMIN)
{
if ($userdata['user_id'] != $row['article_poster'])
{
trigger_error('您没有权限修改');
}
if (((time() - $row['article_time']) > 86400))
{
trigger_error('这篇文章为历史文章(时间超过一天)不能编辑');
}
}
else
{
$template->assign_block_vars('admin', array(
'CLASS_MANAGE' => append_sid('article.php?mode=manage&b=edit&i=' . $edit_id),
'CLASS_CREATE' => append_sid('article.php?mode=manage&m=create&b=edit&i=' . $edit_id))
);
}
if (isset($_POST['submit']))
{
$title = get_var('title', '');
$class = get_var('class', '');
$text = get_var('text', '');
$error = false;
$error_msg = '';
if (empty($title))
{
$error = true;
$error_msg = '<p>文章标题不能为空</p>';
}
if (empty($class))
{
$error = true;
$error_msg = '<p>必需选择文章分类</p>';
}
if (empty($text))
{
$error = true;
$error_msg = '<p>文章内容不能为空</p>';
}
if (!$error)
{
$sql_ary = array(
'article_title' => $title,
'article_class' => $class,
'article_text' => $text
);
$sql = 'UPDATE ' . ARTICLES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
WHERE article_id = ' . $edit_id;
if (!$db->sql_query($sql))
{
trigger_error('无法修改文章', E_USER_WARNING);
}
trigger_error('文章修改成功' . back_link(append_sid('article.php?mode=view&id=' . $edit_id)));
}
}
page_header('修改文章');
if ( $error )
{
error_box('ERROR_BOX', $error_msg);
}
$template->assign_vars(array(
'L_TITLE' => '修改文章',
'ARTICLE_TITLE' => $row['article_title'],
'ARTICLE_TEXT' => $row['article_text'],
'ARTICLE_CLASS' => article_class_select($row['article_class'], $article_class),
'U_BACK' => append_sid('article.php?mode=view&id=' . $edit_id),
'S_ACTION' => append_sid('article.php?mode=edit&id=' . $edit_id))
);
$template->set_filenames(array(
'body' => 'article/article_edit.tpl')
);
$template->pparse('body');
page_footer();
}
elseif ($mode == 'post')
{
if (!$userdata['session_logged_in'])
{
trigger_error('请先登录');
}
$error = false;
$error_msg = '';
if (isset($_POST['submit']))
{
$title = get_var('title', '');
$class = get_var('class', '');
$text = get_var('text', '');
if (empty($title))
{
$error = true;
$error_msg = '<p>文章标题不能为空</p>';
}
if (empty($class))
{
$error = true;
$error_msg = '<p>必需选择文章分类</p>';
}
if (empty($text))
{
$error = true;
$error_msg = '<p>文章内容不能为空</p>';
}
if (!$error)
{
$sql = 'SELECT MAX(article_id) AS max_id
FROM ' . ARTICLES_TABLE;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法取得文章的ID', E_USER_WARNING);
}
$row = $db->sql_fetchrow($result);
$new_article_id = $row['max_id'] + 1;
$sql_ary = array(
'article_id' => $new_article_id,
'article_poster' => $userdata['user_id'],
'article_time' => time(),
'article_views' => 0,
'article_title' => $title,
'article_class' => $class,
'article_text' => $text
);
$sql = 'INSERT INTO ' . ARTICLES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
if (!$db->sql_query($sql))
{
trigger_error('无法发表文章', E_USER_WARNING);
}
trigger_error('发表成功' . back_link(append_sid('article.php?mode=view&id=' . $new_article_id)));
}
}
if ($userdata['user_level'] == ADMIN)
{
$template->assign_block_vars('admin', array(
'CLASS_MANAGE' => append_sid('article.php?mode=manage&b=post'),
'CLASS_CREATE' => append_sid('article.php?mode=manage&m=create&b=post'))
);
}
page_header('发表文章');
if ( $error )
{
error_box('ERROR_BOX', $error_msg);
}
$template->assign_vars(array(
'L_TITLE' => '发表文章',
'ARTICLE_TITLE' => '',
'ARTICLE_TEXT' => '',
'ARTICLE_CLASS' => article_class_select($row['article_class'], $article_class),
'U_BACK' => append_sid('article.php'),
'S_ACTION' => append_sid('article.php?mode=post'))
);
$template->set_filenames(array(
'body' => 'article/article_edit.tpl')
);
$template->pparse('body');
page_footer();
}
elseif ($mode == 'delete')
{
if (!$userdata['session_logged_in'])
{
trigger_error('请先登录');
}
if (!isset($_GET['id']))
{
trigger_error('请指定要删除的文章');
}
$delete_id = intval($_GET['id']);
$sql = 'SELECT article_title, article_class
FROM ' . ARTICLES_TABLE . '
WHERE article_id = ' . $delete_id;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询要删除的文章信息', E_USER_WARNING);
}
if (!$row = $db->sql_fetchrow($result))
{
trigger_error('您要删除的文章不存在');
}
if ($userdata['user_level'] != ADMIN)
{
if ($userdata['user_id'] != $row['article_poster'])
{
trigger_error('您没有权限删除');
}
if (((time() - $row['article_time']) > 86400))
{
trigger_error('这篇文章为历史文章(时间超过一天)不能删除');
}
}
if ( isset($_POST['cancel']) )
{
redirect(append_sid('article.php?mode=view&id=' . $delete_id, true));
}
$confirm = ( isset($_POST['confirm']) ) ? ( ( $_POST['confirm'] ) ? true : false ) : false;
if( $confirm )
{
$sql = 'DELETE FROM ' . ARTICLES_TABLE . '
WHERE article_id = ' . $delete_id;
if (!$db->sql_query($sql))
{
trigger_error('无法删除', E_USER_WARNING);
}
trigger_error('删除成功' . back_link(append_sid('article.php?mode=cat&id=' . $row['article_class'])));
}
page_header('删除文章');
$template->set_filenames(array(
'confirm' => 'confirm_body.tpl')
);
$template->assign_vars(array(
'MESSAGE_TITLE' => '删除文章',
'MESSAGE_TEXT' => '是否删除 “' . $row['article_title'] . '” 这篇文章?',
'L_YES' => '是',
'L_NO' => '否',
'S_CONFIRM_ACTION' => append_sid('article.php?mode=delete&id=' . $delete_id))
);
$template->pparse('confirm');
page_footer();
}
elseif ($mode == 'manage')
{
if (!$userdata['session_logged_in'])
{
trigger_error('请先登录');
}
if ($userdata['user_level'] != ADMIN)
{
trigger_error('您没有权限');
}
$manage = isset($_GET['m']) ? $_GET['m'] : '';
switch ($manage)
{
case 'create':
$back_url = append_sid('article.php');
$create_url = append_sid('article.php?mode=manage&m=create');
if (isset($_GET['i']) && isset($_GET['b']))
{
if ($_GET['b'] == 'edit' && $_GET['i'])
{
$back_url = append_sid('article.php?mode=edit&id=' . (int) $_GET['i']);
$create_url = append_sid('article.php?mode=manage&m=create&b=edit&i=' . (int) $_GET['i']);
}
else if ($_GET['b'] == 'post')
{
$back_url = append_sid('article.php?mode=post');
$create_url = append_sid('article.php?mode=manage&m=create&b=post');
}
}
if (isset($_POST['name']) && isset($_POST['sort']))
{
if (empty($_POST['name']))
{
trigger_error('分类名不能留空' . back_link($create_url));
}
$sort = intval($_POST['sort']);
$sql = 'INSERT INTO ' . ARTICLES_CLASS_TABLE . " (ac_name, ac_sort)
VALUES ('{$_POST['name']}', $sort)";
if (!$db->sql_query($sql))
{
trigger_error('无法创建分类', E_USER_WARNING);
}
trigger_error('创建成功' . back_link($back_url));
}
trigger_error('<form action="' . $create_url . '" method="post">名称:<input type="text" name="name" value="" />排序:<input type="text" name="sort" size="3" value="" /><input type="submit" value="添加" /></form>');
break;
case 'delete':
$delete_id = (int) $_GET['i'];
$sql = 'SELECT ac_name
FROM ' . ARTICLES_CLASS_TABLE . '
WHERE ac_id = ' . $delete_id;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询要删除的文章分类信息', E_USER_WARNING);
}
if (!$row = $db->sql_fetchrow($result))
{
trigger_error('此分类不存在或已被删除' . back_link(append_sid('article.php?mode=manage')));
}
if ( isset($_POST['cancel']) )
{
redirect(append_sid('article.php?mode=manage', true));
}
$confirm = ( isset($_POST['confirm']) ) ? ( ( $_POST['confirm'] ) ? true : false ) : false;
if ($confirm)
{
$class_id = intval($_POST['class']);
if ($delete_id == $class_id)
{
$sql = 'DELETE FROM ' . ARTICLES_TABLE . '
WHERE article_class = ' . $delete_id;
if (!$db->sql_query($sql))
{
trigger_error('无法删除文章数据', E_USER_WARNING);
}
}
else
{
$sql = 'UPDATE ' . ARTICLES_TABLE . '
SET article_class = ' . $class . '
WHERE article_class = ' . $delete_id;
if (!$db->sql_query($sql))
{
trigger_error('无法转移文章数据', E_USER_WARNING);
}
}
$sql = 'DELETE FROM ' . ARTICLES_CLASS_TABLE . '
WHERE ac_id = ' . $delete_id;
if (!$db->sql_query($sql))
{
trigger_error('无法删除文章分类', E_USER_WARNING);
}
trigger_error('操作成功!' . back_link(append_sid('article.php?mode=manage')));
}
$s_hidden = '<p>删除后把该分类的文章移动到:';
$s_hidden .= article_class_select($delete_id, $article_class);
$s_hidden .= '<br /><span class="red">选择当前分类表示删除该分类的文章</span></p>';
confirm_box(
'删除文章分类',
'删除文章分类',
'是否删除文章分类“' . $row['ac_name'] . '”?',
append_sid('article.php?mode=manage&m=delete&i=' . $delete_id),
$s_hidden
);
break;
case 'edit':
$edit_id = (int) $_GET['i'];
$sql = 'SELECT ac_name, ac_sort
FROM ' . ARTICLES_CLASS_TABLE . '
WHERE ac_id = ' . $edit_id;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询要修改的文章分类信息', E_USER_WARNING);
}
if (!$row = $db->sql_fetchrow($result))
{
trigger_error('此分类不存在' . back_link(append_sid('article.php?mode=manage')));
}
if (isset($_POST['name']) && isset($_POST['sort']))
{
if (empty($_POST['name']))
{
trigger_error('分类名不能留空' . back_link($create_url));
}
$sort = intval($_POST['sort']);
$sql = 'UPDATE ' . ARTICLES_CLASS_TABLE . "
SET ac_name = '{$_POST['name']}', ac_sort = $sort
WHERE ac_id = " . $edit_id;
if (!$db->sql_query($sql))
{
trigger_error('无法修改分类', E_USER_WARNING);
}
trigger_error('修改成功' . back_link(append_sid('article.php?mode=manage')));
}
trigger_error('<form action="' . $create_url . '" method="post">名称:<input type="text" name="name" value="' . $row['ac_name'] . '" />排序:<input type="text" name="sort" size="3" value="' . $row['ac_sort'] . '" /><input type="submit" value="修改" /></form>');
break;
default:
page_header('文章分类管理');
$i = 0;
foreach ($article_class as $key => $value)
{
$row_class = ( !($i % 2) ) ? 'row1' : 'row2';
$template->assign_block_vars('class_list', array(
'ROW_CLASS' => $row_class,
'CLASS_NAME' => $value,
'U_EDIT' => append_sid('article.php?mode=manage&m=edit&i=' . $key),
'U_DELETE' => append_sid('article.php?mode=manage&m=delete&i=' . $key))
);
$i++;
}
$template->set_filenames(array(
'body' => 'article/article_class_manage.tpl')
);
$template->assign_var('U_BACK', append_sid('article.php'));
$template->pparse('body');
page_footer();
break;
}
}
elseif ($mode == 'approval')
{
if (!$userdata['session_logged_in'])
{
trigger_error('请先登录');
}
if ($userdata['user_level'] != ADMIN)
{
trigger_error('您没有权限');
}
$submit = isset($_POST['submit']) ? true : false;
$id_list = get_var('id_list', array(0));
if ($submit && count($id_list) > 0)
{
//$sql = 'DELETE FROM ' . ARTICLES_TABLE . '
// WHERE article_id IN (' . implode(', ', $id_list) . ')
// AND link_admin_user = ' . (int) $userdata['user_id'];
$sql = 'UPDATE ' . ARTICLES_TABLE . '
SET article_approval = 1
WHERE article_id IN (' . implode(', ', $id_list) . ')';
if (!$db->sql_query($sql))
{
trigger_error('文章无法进行审核', E_USER_WARNING);
}
trigger_error('操作成功!' . back_link(append_sid('article.php?mode=approval')));
}
$per = $board_config['topics_per_page'];
$start = get_pagination_start($per);
$sql = 'SELECT article_id, article_title
FROM ' . ARTICLES_TABLE . '
WHERE article_approval = 0
ORDER BY article_time DESC
LIMIT ' . $start . ', ' . $per;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询待审核的文章数据', E_USER_WARNING);
}
$i = 0;
while ($row = $db->sql_fetchrow($result))
{
$row_class = ( !($i % 2) ) ? 'row1' : 'row2';
$template->assign_block_vars('approval', array(
'ROW_CLASS' => $row_class,
'ARTICLE_TITLE' => $row['article_title'],
'ARTICLE_ID' => $row['article_id'],
'U_ARTICLE' => append_sid('article.php?mode=view&id=' . $row['article_id']))
);
$i++;
}
$sql = 'SELECT COUNT(article_id) AS total
FROM ' . ARTICLES_TABLE . '
WHERE article_approval = 0';
if (!$result = $db->sql_query($sql))
{
trigger_error('无法统计未审核的文章');
}
$row = $db->sql_fetchrow($result);
if (!$row['total'])
{
$template->assign_block_vars('not_approval', array());
}
$pagination = generate_pagination('article.php?mode=approval', $row['total'], $per, $start);
page_header('等待审核的文章');
$template->set_filenames(array(
'body' => 'article/article_approval.tpl')
);
$template->assign_vars(array(
'PAGINATION' => $pagination,
'U_BACK' => append_sid('article.php'),
'S_ACTION' => append_sid('article.php?mode=approval'))
);
$template->pparse('body');
page_footer();
}
// 显示30天热门文章
$sql = 'SELECT article_id, article_class, article_title
FROM ' . ARTICLES_TABLE . '
WHERE article_time >= ' . (time() - 2592000) . '
AND article_approval = 1
ORDER BY article_views, article_time DESC
LIMIT 0, 5';
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询热门文章数据', E_USER_WARNING);
}
if (!$db->sql_numrows($result))
{
$template->assign_block_vars('not_hot', array());
}
while ($row = $db->sql_fetchrow($result))
{
$ac_name = (isset($article_class[$row['article_class']])) ? $article_class[$row['article_class']] : '未知';
$template->assign_block_vars('article_hot', array(
'ARTICLE_TITLE' => $row['article_title'],
'U_ARTICLE' => append_sid('article.php?mode=view&id=' . $row['article_id']),
'ARTICLE_NAME' => $ac_name)
);
}
// 显示热门文章
$sql = 'SELECT article_id, article_class, article_title
FROM ' . ARTICLES_TABLE . '
WHERE article_approval = 1
ORDER BY article_time DESC
LIMIT 0, 10';
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询最新文章数据', E_USER_WARNING);
}
if (!$db->sql_numrows($result))
{
$template->assign_block_vars('not_new', array());
}
while ($row = $db->sql_fetchrow($result))
{
$ac_name = (isset($article_class[$row['article_class']])) ? $article_class[$row['article_class']] : '未知';
$template->assign_block_vars('article_new', array(
'ARTICLE_TITLE' => $row['article_title'],
'U_ARTICLE' => append_sid('article.php?mode=view&id=' . $row['article_id']),
'ARTICLE_NAME' => $ac_name)
);
}
page_header('文章');
$template->set_filenames(array(
'body' => 'article/article_body.tpl')
);
if ($userdata['user_level'] == ADMIN)
{
$template->assign_block_vars('admin', array());
}
$template->assign_vars(array(
'U_BACK' => append_sid('index.php'),
'U_NEW_ARTICLE' => append_sid('article.php?mode=post'),
'U_APPROVAL' => append_sid('article.php?mode=approval'))
);
$template->pparse('body');
page_footer();
?>