1
+ <?php
2
+ # -- BEGIN LICENSE BLOCK ----------------------------------
3
+ #
4
+ # This file is part of postslistOptions, a plugin for Dotclear 2.
5
+ #
6
+ # Copyright (c) 2009-2013 Jean-Christian Denis and contributors
7
+ # contact@jcdenis.fr http://jcd.lv
8
+ #
9
+ # Licensed under the GPL version 2.0 license.
10
+ # A copy of this license is available in LICENSE file or at
11
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12
+ #
13
+ # -- END LICENSE BLOCK ------------------------------------
14
+
15
+ if (!defined ('DC_CONTEXT_ADMIN ' )){return ;}
16
+
17
+ if (!$ core ->auth ->check ('admin ' ,$ core ->blog ->id )) { return ; }
18
+
19
+ $ core ->addBehavior ('adminPostsActionsCombo ' ,array ('behaviorsPostlistOptions ' ,'adminPostsActionsCombo ' ));
20
+ $ core ->addBehavior ('adminPostsActionsContent ' ,array ('behaviorsPostlistOptions ' ,'adminPostsActionsContent ' ));
21
+ $ core ->addBehavior ('adminPostsActions ' ,array ('behaviorsPostlistOptions ' ,'adminPostsActions ' ));
22
+
23
+ class behaviorsPostlistOptions
24
+ {
25
+ public static function adminPostsActionsCombo ($ args )
26
+ {
27
+ if (!$ GLOBALS ['core ' ]->auth ->check ('admin ' ,$ GLOBALS ['core ' ]->blog ->id )) return ;
28
+
29
+ $ args [0 ][__ ('Comments ' )][__ ('Mark as opened ' )] = 'commentsopen ' ;
30
+ $ args [0 ][__ ('Comments ' )][__ ('Mark as closed ' )] = 'commentsclose ' ;
31
+ $ args [0 ][__ ('Comments ' )][__ ('Delete all comments ' )] = 'commentsdelete ' ;
32
+ $ args [0 ][__ ('Trackbacks ' )][__ ('Mark as opened ' )] = 'trackbacksopen ' ;
33
+ $ args [0 ][__ ('Trackbacks ' )][__ ('Mark as closed ' )] = 'trackbacksclose ' ;
34
+ $ args [0 ][__ ('Trackbacks ' )][__ ('Delete all trackbacks ' )] = 'trackbacksdelete ' ;
35
+ }
36
+
37
+ public static function adminPostsActionsContent ($ core ,$ action ,$ hidden_fields )
38
+ {
39
+ $ allow = array (
40
+ 'commentsdelete ' => __ ('Are you sure you want to delete all comments? ' ),
41
+ 'trackbacksdelete ' => __ ('Are you sure you want to delete all trackbacks? ' )
42
+ );
43
+
44
+ if (!isset ($ allow [$ action ])
45
+ || !$ core ->auth ->check ('admin ' ,$ core ->blog ->id )){ return ; }
46
+
47
+ echo
48
+ '<h3> ' .__ ('Confirm action ' ).'</h3> ' .
49
+ '<form action="posts_actions.php" method="post"> ' .
50
+ '<p> ' .$ allow [$ action ].'</p> ' .
51
+ '<p> ' .$ hidden_fields .$ core ->formNonce ().
52
+ form::hidden (array ('action ' ),'confirmed ' .$ action ).
53
+ '<input type="submit" value=" ' .__ ('yes ' ).'" /></p> ' .
54
+ '</form> ' ;
55
+ }
56
+
57
+ public static function adminPostsActions ($ core ,$ posts ,$ action ,$ redir )
58
+ {
59
+ $ allow = array (
60
+ 'commentsopen ' ,'commentsclose ' ,'confirmedcommentsdelete ' ,
61
+ 'trackbacksopen ' ,'trackbacksclose ' ,'confirmedtrackbacksdelete '
62
+ );
63
+ if (!in_array ($ action ,$ allow )
64
+ || !$ core ->auth ->check ('admin ' ,$ core ->blog ->id )){ return ; }
65
+
66
+ try {
67
+ while ($ posts ->fetch ())
68
+ {
69
+ $ id = $ posts ->post_id ;
70
+
71
+ switch ($ action ) {
72
+ case 'commentsopen ' :
73
+ self ::updPostOption ($ id ,'post_open_comment ' ,1 );
74
+ break ;
75
+
76
+ case 'commentsclose ' :
77
+ self ::updPostOption ($ id ,'post_open_comment ' ,0 );
78
+ break ;
79
+
80
+ case 'trackbacksopen ' :
81
+ self ::updPostOption ($ id ,'post_open_tb ' ,1 );
82
+ break ;
83
+
84
+ case 'trackbacksclose ' :
85
+ self ::updPostOption ($ id ,'post_open_tb ' ,0 );
86
+ break ;
87
+
88
+ case 'confirmedcommentsdelete ' :
89
+ self ::delPostComments ($ id ,false );
90
+ self ::updPostOption ($ id ,'nb_comment ' ,0 );
91
+ break ;
92
+
93
+ case 'confirmedtrackbacksdelete ' :
94
+ self ::delPostComments ($ id ,true );
95
+ self ::updPostOption ($ id ,'nb_trackback ' ,0 );
96
+ break ;
97
+ }
98
+ }
99
+ if (!$ core ->error ->flag ()) {
100
+ http::redirect ($ redir );
101
+ }
102
+ }
103
+ catch (Exception $ e )
104
+ {
105
+ $ core ->error ->add ($ e ->getMessage ());
106
+ }
107
+ }
108
+
109
+ private static function updPostOption ($ id ,$ option ,$ value )
110
+ {
111
+ global $ core ;
112
+
113
+ if (!$ core ->auth ->check ('admin ' ,$ core ->blog ->id )) {
114
+ throw new Exception (__ ('You are not allowed to change this entry option ' ));
115
+ }
116
+
117
+ $ id = abs ((integer ) $ id );
118
+ $ cur = $ core ->con ->openCursor ($ core ->prefix .'post ' );
119
+
120
+ $ cur ->{$ option } = $ value ;
121
+ $ cur ->post_upddt = date ('Y-m-d H:i:s ' );
122
+
123
+ $ cur ->update (
124
+ 'WHERE post_id = ' .$ id .' ' .
125
+ "AND blog_id = ' " .$ core ->con ->escape ($ core ->blog ->id )."' "
126
+ );
127
+ $ core ->blog ->triggerBlog ();
128
+ }
129
+
130
+ private static function delPostComments ($ id ,$ tb =false )
131
+ {
132
+ global $ core ;
133
+
134
+ $ params = array (
135
+ 'no_content ' => true ,
136
+ 'post_id ' => abs ((integer ) $ id ),
137
+ 'comment_trackback ' => $ tb ? 1 : 0
138
+ );
139
+ $ comments = $ core ->blog ->getComments ($ params );
140
+
141
+ while ($ comments ->fetch ())
142
+ {
143
+ // slower but preserve core behaviors
144
+ $ core ->blog ->delComment ($ comments ->comment_id );
145
+ }
146
+ }
147
+ }
148
+ ?>
0 commit comments