1111
1212use FeatherBB \Core \Url ;
1313use FeatherBB \Core \Utils ;
14+ use FeatherBB \Core \Error ;
1415use FeatherBB \Core \Track ;
1516
1617class Forum
@@ -26,7 +27,7 @@ public function __construct()
2627 public function display ($ fid , $ name = null , $ page = null )
2728 {
2829 // Fetch some informations about the forum
29- $ cur_forum = $ this ->model ->get_info_forum ($ fid );
30+ $ cur_forum = $ this ->model ->get_forum_info ($ fid );
3031
3132 // Is this a redirect forum? In that case, redirect!
3233 if ($ cur_forum ['redirect_url ' ] != '' ) {
@@ -92,24 +93,169 @@ public function display($fid, $name = null, $page = null)
9293 ))->addTemplate ('Forum.php ' )->display ();
9394 }
9495
95- public function markread ($ id , $ name = '' )
96+ public function moderate ($ id , $ name = null , $ page = null )
97+ {
98+ // Make sure that only admmods allowed access this page
99+ $ moderators = $ this ->model ->get_moderators ($ id );
100+ $ mods_array = ($ moderators != '' ) ? unserialize ($ moderators ) : array ();
101+
102+ if ($ this ->feather ->user ->g_id != $ this ->feather ->forum_env ['FEATHER_ADMIN ' ] && ($ this ->feather ->user ->g_moderator == '0 ' || !array_key_exists ($ this ->feather ->user ->username , $ mods_array ))) {
103+ throw new Error (__ ('No permission ' ), 403 );
104+ }
105+
106+ // Fetch some info about the forum
107+ $ cur_forum = $ this ->model ->get_forum_info ($ id );
108+
109+ // Is this a redirect forum? In that case, abort!
110+ if ($ cur_forum ['redirect_url ' ] != '' ) {
111+ throw new Error (__ ('Bad request ' ), '404 ' );
112+ }
113+
114+ $ sort_by = $ this ->model ->sort_forum_by ($ cur_forum ['sort_by ' ]);
115+
116+ // Determine the topic offset (based on $_GET['p'])
117+ $ num_pages = ceil ($ cur_forum ['num_topics ' ] / $ this ->feather ->user ->disp_topics );
118+
119+ $ p = (!isset ($ page ) || $ page <= 1 || $ page > $ num_pages ) ? 1 : intval ($ page );
120+ $ start_from = $ this ->feather ->user ->disp_topics * ($ p - 1 );
121+ $ url_forum = Url::url_friendly ($ cur_forum ['forum_name ' ]);
122+
123+ $ this ->feather ->template ->setPageInfo (array (
124+ 'title ' => array (Utils::escape ($ this ->feather ->config ['o_board_title ' ]), Utils::escape ($ cur_forum ['forum_name ' ])),
125+ 'active_page ' => 'moderate ' ,
126+ 'page ' => $ p ,
127+ 'id ' => $ id ,
128+ 'p ' => $ p ,
129+ 'url_forum ' => $ url_forum ,
130+ 'cur_forum ' => $ cur_forum ,
131+ 'paging_links ' => '<span class="pages-label"> ' .__ ('Pages ' ).' </span> ' .Url::paginate ($ num_pages , $ p , 'moderate/forum/ ' .$ id .'/# ' ),
132+ 'topic_data ' => $ this ->model ->display_topics_moderate ($ id , $ sort_by , $ start_from ),
133+ 'start_from ' => $ start_from ,
134+ )
135+ )->addTemplate ('moderate/moderator_forum.php ' )->display ();
136+ }
137+
138+ public function markread ($ id )
96139 {
97140 $ tracked_topics = Track::get_tracked_topics ();
98141 $ tracked_topics ['forums ' ][$ id ] = time ();
99142 Track::set_tracked_topics ($ tracked_topics );
100143
101- Url::redirect ($ this ->feather ->urlFor ('Forum ' , ['id ' => $ id, ' name ' => $ name ]), __ ('Mark forum read redirect ' ));
144+ Url::redirect ($ this ->feather ->urlFor ('Forum ' , ['id ' => $ id ]), __ ('Mark forum read redirect ' ));
102145 }
103146
104- public function subscribe ($ id, $ name = '' )
147+ public function subscribe ($ id )
105148 {
106149 $ this ->model ->subscribe ($ id );
107- Url::redirect ($ this ->feather ->urlFor ('Forum ' , ['id ' => $ forum_id , ' name ' => $ name ]), __ ('Subscribe redirect ' ));
150+ Url::redirect ($ this ->feather ->urlFor ('Forum ' , ['id ' => $ id ]), __ ('Subscribe redirect ' ));
108151 }
109152
110- public function unsubscribe ($ id, $ name = '' )
153+ public function unsubscribe ($ id )
111154 {
112155 $ this ->model ->unsubscribe ($ id );
113- Url::redirect ($ this ->feather ->urlFor ('Forum ' , ['id ' => $ forum_id , 'name ' => $ name ]), __ ('Unsubscribe redirect ' ));
156+ Url::redirect ($ this ->feather ->urlFor ('Forum ' , ['id ' => $ id ]), __ ('Unsubscribe redirect ' ));
157+ }
158+
159+ public function dealposts ($ fid , $ page )
160+ {
161+ // Make sure that only admmods allowed access this page
162+ $ moderators = $ this ->model ->get_moderators ($ fid );
163+ $ mods_array = ($ moderators != '' ) ? unserialize ($ moderators ) : array ();
164+
165+ if ($ this ->feather ->user ->g_id != $ this ->feather ->forum_env ['FEATHER_ADMIN ' ] && ($ this ->feather ->user ->g_moderator == '0 ' || !array_key_exists ($ this ->feather ->user ->username , $ mods_array ))) {
166+ throw new Error (__ ('No permission ' ), 403 );
167+ }
168+
169+ $ topicModel = new \FeatherBB \Model \Topic ();
170+
171+ // Move one or more topics
172+ if ($ this ->feather ->request ->post ('move_topics ' ) || $ this ->feather ->request ->post ('move_topics_to ' )) {
173+ $ topics = $ this ->feather ->request ->post ('topics ' ) ? $ this ->feather ->request ->post ('topics ' ) : array ();
174+ if (empty ($ topics )) {
175+ throw new Error (__ ('No topics selected ' ), 400 );
176+ }
177+
178+ if ($ new_fid = $ this ->feather ->request ->post ('move_to_forum ' )) {
179+ $ topics = explode (', ' , $ topics );
180+ $ topicModel ->move_to ($ fid , $ new_fid , $ topics );
181+ Url::redirect ($ this ->feather ->urlFor ('Forum ' , ['id ' => $ new_fid ]), __ ('Move topics redirect ' ));
182+ }
183+
184+ // Check if there are enough forums to move the topic
185+ if ( !$ topicModel ->check_move_possible () ) {
186+ throw new Error (__ ('Nowhere to move ' ), 403 );
187+ }
188+
189+ $ this ->feather ->template ->setPageInfo (array (
190+ 'action ' => 'multi ' ,
191+ 'title ' => array (Utils::escape ($ this ->feather ->config ['o_board_title ' ]), __ ('Moderate ' )),
192+ 'active_page ' => 'moderate ' ,
193+ 'id ' => $ fid ,
194+ 'topics ' => implode (', ' , array_map ('intval ' , array_keys ($ topics ))),
195+ 'list_forums ' => $ topicModel ->get_forum_list_move ($ fid ),
196+ )
197+ )->addTemplate ('moderate/move_topics.php ' )->display ();
198+ }
199+
200+ // Merge two or more topics
201+ elseif ($ this ->feather ->request ->post ('merge_topics ' ) || $ this ->feather ->request ->post ('merge_topics_comply ' )) {
202+ if ($ this ->feather ->request ->post ('merge_topics_comply ' )) {
203+ $ this ->model ->merge_topics ($ fid );
204+ Url::redirect ($ this ->feather ->urlFor ('Forum ' , array ('id ' => $ fid )), __ ('Merge topics redirect ' ));
205+ }
206+
207+ $ topics = $ this ->feather ->request ->post ('topics ' ) ? $ this ->feather ->request ->post ('topics ' ) : array ();
208+ if (count ($ topics ) < 2 ) {
209+ throw new Error (__ ('Not enough topics selected ' ), 400 );
210+ }
211+
212+ $ this ->feather ->template ->setPageInfo (array (
213+ 'title ' => array (Utils::escape ($ this ->feather ->config ['o_board_title ' ]), __ ('Moderate ' )),
214+ 'active_page ' => 'moderate ' ,
215+ 'id ' => $ fid ,
216+ 'topics ' => $ topics ,
217+ )
218+ )->addTemplate ('moderate/merge_topics.php ' )->display ();
219+ }
220+
221+ // Delete one or more topics
222+ elseif ($ this ->feather ->request ->post ('delete_topics ' ) || $ this ->feather ->request ->post ('delete_topics_comply ' )) {
223+ $ topics = $ this ->feather ->request ->post ('topics ' ) ? $ this ->feather ->request ->post ('topics ' ) : array ();
224+ if (empty ($ topics )) {
225+ throw new Error (__ ('No topics selected ' ), 400 );
226+ }
227+
228+ if ($ this ->feather ->request ->post ('delete_topics_comply ' )) {
229+ $ this ->model ->delete_topics ($ topics , $ fid );
230+ Url::redirect ($ this ->feather ->urlFor ('Forum ' , array ('id ' => $ fid )), __ ('Delete topics redirect ' ));
231+ }
232+
233+ $ this ->feather ->template ->setPageInfo (array (
234+ 'title ' => array (Utils::escape ($ this ->feather ->config ['o_board_title ' ]), __ ('Moderate ' )),
235+ 'active_page ' => 'moderate ' ,
236+ 'id ' => $ fid ,
237+ 'topics ' => $ topics ,
238+ )
239+ )->addTemplate ('moderate/delete_topics.php ' )->display ();
240+ }
241+
242+
243+ // Open or close one or more topics
244+ elseif ($ this ->feather ->request ->post ('open ' ) || $ this ->feather ->request ->post ('close ' )) {
245+ $ action = ($ this ->feather ->request ->post ('open ' )) ? 0 : 1 ;
246+
247+ // There could be an array of topic IDs in $_POST
248+ if ($ this ->feather ->request ->post ('open ' ) || $ this ->feather ->request ->post ('close ' )) {
249+ $ topics = $ this ->feather ->request ->post ('topics ' ) ? @array_map ('intval ' , @array_keys ($ this ->feather ->request ->post ('topics ' ))) : array ();
250+ if (empty ($ topics )) {
251+ throw new Error (__ ('No topics selected ' ), 400 );
252+ }
253+
254+ $ this ->model ->close_multiple_topics ($ action , $ topics );
255+
256+ $ redirect_msg = ($ action ) ? __ ('Close topics redirect ' ) : __ ('Open topics redirect ' );
257+ Url::redirect ($ this ->feather ->urlFor ('moderateForum ' , array ('fid ' => $ fid , 'page ' => $ page )), $ redirect_msg );
258+ }
259+ }
114260 }
115261}
0 commit comments