11<?php
22
3+ declare (strict_types=1 );
4+
35/* For licensing terms, see /license.txt */
46
57use Chamilo \CoreBundle \Enums \ActionIcon ;
@@ -89,12 +91,14 @@ function setFocus() {
8991}
9092
9193$ repoThread = Container::getForumThreadRepository ();
94+
9295/** @var CForumThread $threadEntity */
9396$ threadEntity = $ repoThread ->find ($ threadId );
9497
9598if (empty ($ threadEntity )) {
9699 $ url = api_get_path (WEB_CODE_PATH ).'forum/viewforum.php? ' .api_get_cidreq ().'&forum= ' .$ forumId ;
97100 header ('Location: ' .$ url );
101+
98102 exit ;
99103}
100104
@@ -162,13 +166,14 @@ function setFocus() {
162166 case 'delete_attach ' :
163167 delete_attachment ($ _GET ['post ' ], $ _GET ['id_attach ' ]);
164168 header ('Location: ' .$ currentUrl );
169+
165170 exit ;
171+
166172 case 'delete ' :
167173 if (
168- isset ($ _GET ['content ' ]) &&
169- isset ($ _GET ['id ' ]) &&
170- (api_is_allowed_to_edit (false , true ) ||
171- ($ groupEntity && GroupManager::isTutorOfGroup (api_get_user_id (), $ groupEntity )))
174+ isset ($ _GET ['content ' ], $ _GET ['id ' ])
175+ && (api_is_allowed_to_edit (false , true )
176+ || ($ groupEntity && GroupManager::isTutorOfGroup (api_get_user_id (), $ groupEntity )))
172177 ) {
173178 /** @var CForumPost $postEntity */
174179 $ postEntity = $ repoPost ->find ($ _GET ['id ' ]);
@@ -177,20 +182,24 @@ function setFocus() {
177182 }
178183 }
179184 header ('Location: ' .$ currentUrl );
185+
180186 exit ;
187+
181188 case 'invisible ' :
182189 case 'visible ' :
183- if (isset ($ _GET ['id ' ]) &&
184- (api_is_allowed_to_edit (false , true ) ||
185- ($ groupEntity && GroupManager::isTutorOfGroup (api_get_user_id (), $ groupEntity )))
190+ if (isset ($ _GET ['id ' ])
191+ && (api_is_allowed_to_edit (false , true )
192+ || ($ groupEntity && GroupManager::isTutorOfGroup (api_get_user_id (), $ groupEntity )))
186193 ) {
187194 /** @var CForumPost $postEntity */
188195 $ postEntity = $ repoPost ->find ($ _GET ['id ' ]);
189196 $ message = approvePost ($ postEntity , $ _GET ['action ' ]);
190197 Display::addFlash (Display::return_message (get_lang ($ message )));
191198 }
192199 header ('Location: ' .$ currentUrl );
200+
193201 exit ;
202+
194203 case 'move ' :
195204 if (isset ($ _GET ['post ' ])) {
196205 $ form = move_post_form ();
@@ -202,24 +211,28 @@ function setFocus() {
202211 'forum/viewthread.php?forum= ' .$ forumId .'& ' .api_get_cidreq ().'&thread= ' .$ threadId ;
203212
204213 header ('Location: ' .$ currentUrl );
214+
205215 exit ;
206- } else {
207- $ moveForm = $ form ->returnForm ();
208216 }
217+ $ moveForm = $ form ->returnForm ();
209218 }
210219
211220 break ;
221+
212222 case 'report ' :
213223 $ result = reportPost ($ postEntity , $ forumEntity , $ threadEntity );
214224 Display::addFlash (Display::return_message (get_lang ('Reported ' )));
215225 header ('Location: ' .$ currentUrl );
226+
216227 exit ;
228+
217229 case 'ask_revision ' :
218230 if ('true ' === api_get_setting ('forum.allow_forum_post_revisions ' )) {
219231 $ result = savePostRevision ($ postEntity );
220232 Display::addFlash (Display::return_message (get_lang ('Saved. ' )));
221233 }
222234 header ('Location: ' .$ currentUrl );
235+
223236 exit ;
224237}
225238
@@ -246,8 +259,8 @@ function setFocus() {
246259 if ('learnpath ' != $ origin ) {
247260 $ interbreadcrumb [] = [
248261 'url ' => api_get_path (WEB_CODE_PATH ).'forum/index.php? ' .api_get_cidreq ().'&search= ' .Security::remove_XSS (
249- urlencode ($ my_search )
250- ),
262+ urlencode ($ my_search )
263+ ),
251264 'name ' => $ nameTools ,
252265 ];
253266 $ interbreadcrumb [] = [
@@ -269,10 +282,10 @@ function setFocus() {
269282}
270283
271284// Visibility constraints
272- if (!api_is_allowed_to_create_course () &&
273- (
274- !$ forumEntity ->isVisible ($ courseEntity ) ||
275- !$ threadEntity ->isVisible ($ courseEntity )
285+ if (!api_is_allowed_to_create_course ()
286+ && (
287+ !$ forumEntity ->isVisible ($ courseEntity )
288+ || !$ threadEntity ->isVisible ($ courseEntity )
276289 )
277290) {
278291 api_not_allowed ();
@@ -293,11 +306,10 @@ function setFocus() {
293306 .Display::getMdiIcon (ActionIcon::BACK , 'ch-tool-icon ' , null , ICON_SIZE_MEDIUM , get_lang ('Back to forum ' )).'</a> ' ;
294307}
295308
296- if (($ current_forum_category && 0 == $ current_forum_category ->getLocked ()) &&
297- 0 == $ forumEntity ->getLocked () && 0 == $ threadEntity ->getLocked () || api_is_allowed_to_edit (false , true )
309+ if (($ current_forum_category && 0 == $ current_forum_category ->getLocked ())
310+ && 0 == $ forumEntity ->getLocked () && 0 == $ threadEntity ->getLocked () || api_is_allowed_to_edit (false , true )
298311) {
299312 if ($ _user ['user_id ' ] || (1 == $ forumEntity ->getAllowAnonymous () && !$ _user ['user_id ' ])) {
300-
301313 if ('learnpath ' == $ origin && !empty ($ threadId )) {
302314 $ actions .= '<a href=" ' .$ forumUrl .'viewforum.php?forum= ' .$ forumId .'& ' .api_get_cidreq ().'"> '
303315 .Display::getMdiIcon (ActionIcon::BACK , 'ch-tool-icon ' , null , ICON_SIZE_MEDIUM , get_lang ('Back to forum ' )).'</a> ' ;
@@ -308,9 +320,10 @@ function setFocus() {
308320 .Display::getMdiIcon ('reply ' , 'ch-tool-icon ' , null , ICON_SIZE_MEDIUM , get_lang ('Reply to this thread ' )).'</a> ' ;
309321 }
310322 if ((
311- api_is_allowed_to_edit (false , true ) && !(api_is_session_general_coach ())) ||
312- (1 == $ forumEntity ->getAllowNewThreads () && isset ($ _user ['user_id ' ])) ||
313- (1 == $ forumEntity ->getAllowNewThreads () && !isset ($ _user ['user_id ' ]) && 1 == $ forumEntity ->getAllowAnonymous ())
323+ api_is_allowed_to_edit (false , true ) && !api_is_session_general_coach ()
324+ )
325+ || (1 == $ forumEntity ->getAllowNewThreads () && isset ($ _user ['user_id ' ]))
326+ || (1 == $ forumEntity ->getAllowNewThreads () && !isset ($ _user ['user_id ' ]) && 1 == $ forumEntity ->getAllowAnonymous ())
314327 ) {
315328 if (1 != $ forumEntity ->getLocked () && 1 != $ forumEntity ->getLocked ()) {
316329 $ actions .= ' ' ;
@@ -381,7 +394,8 @@ function setFocus() {
381394 ->where ('fp.thread = :thread ' )
382395 ->setParameter ('thread ' , $ threadId )
383396 ->getQuery ()
384- ->getSingleScalarResult ();
397+ ->getSingleScalarResult ()
398+ ;
385399
386400$ postList = [];
387401foreach ($ posts as $ post ) {
@@ -426,9 +440,9 @@ function setFocus() {
426440 $ editButton = '' ;
427441 $ askForRevision = '' ;
428442
429- if (($ groupEntity && $ tutorGroup ) ||
430- (1 == $ forumEntity ->getAllowEdit () && $ posterId == $ userId ) ||
431- (api_is_allowed_to_edit (false , true ) && !( api_is_session_general_coach () ))
443+ if (($ groupEntity && $ tutorGroup )
444+ || (1 == $ forumEntity ->getAllowEdit () && $ posterId == $ userId )
445+ || (api_is_allowed_to_edit (false , true ) && !api_is_session_general_coach ())
432446 ) {
433447 // pass entity to postIsEditableByStudent() (array caused fatal when calling getStatus())
434448 if (false == $ locked && postIsEditableByStudent ($ forumEntity , $ postEntity )) {
@@ -445,31 +459,31 @@ function setFocus() {
445459 }
446460 }
447461
448- if (($ groupEntity && $ tutorGroup ) || (api_is_allowed_to_edit (false , true ) && !( api_is_session_general_coach () ))) {
462+ if (($ groupEntity && $ tutorGroup ) || (api_is_allowed_to_edit (false , true ) && !api_is_session_general_coach ())) {
449463 if (false == $ locked ) {
450464 $ deleteUrl = api_get_self ().'? ' .api_get_cidreq ().'& ' .http_build_query ([
451- 'forum ' => $ forumId ,
452- 'thread ' => $ threadId ,
453- 'action ' => 'delete ' ,
454- 'content ' => 'post ' ,
455- 'id ' => $ post ['post_id ' ],
456- ]);
465+ 'forum ' => $ forumId ,
466+ 'thread ' => $ threadId ,
467+ 'action ' => 'delete ' ,
468+ 'content ' => 'post ' ,
469+ 'id ' => $ post ['post_id ' ],
470+ ]);
457471 $ iconEdit .= Display::url (
458472 Display::getMdiIcon (ActionIcon::DELETE , 'ch-tool-icon ' , null , ICON_SIZE_SMALL , get_lang ('Delete ' )),
459473 $ deleteUrl ,
460474 [
461475 'class ' => 'inline-flex items-center justify-center w-9 h-9 rounded-lg border border-gray-25 hover:bg-gray-15 ' ,
462476 'title ' => get_lang ('Delete ' ),
463477 'aria-label ' => get_lang ('Delete ' ),
464- 'onclick ' => "if(!confirm(' " .addslashes (api_htmlentities (get_lang ('Are you sure you want to delete this post? Deleting this post will also delete the replies on this post. Please check the threaded view to see which posts will also be deleted ' ), ENT_QUOTES ))."')) return false; " ,
478+ 'onclick ' => "if(!confirm(' " .addslashes (api_htmlentities (get_lang ('Are you sure you want to delete this post? Deleting this post will also delete the replies on this post. Please check the threaded view to see which posts will also be deleted ' ), \ ENT_QUOTES ))."')) return false; " ,
465479 'id ' => "delete-post- {$ post ['post_id ' ]}" ,
466480 ]
467481 );
468482 }
469483 }
470484
471485 // Visibility / Move icons
472- if (api_is_allowed_to_edit (false , true ) && !( api_is_session_general_coach () )) {
486+ if (api_is_allowed_to_edit (false , true ) && !api_is_session_general_coach ()) {
473487 $ iconEdit .= returnVisibleInvisibleIcon (
474488 'post ' ,
475489 $ post ['post_id ' ],
@@ -500,11 +514,11 @@ function setFocus() {
500514 // Build compact "ask revision" icon linking to ?action=ask_revision
501515 if ('true ' === api_get_setting ('forum.allow_forum_post_revisions ' )) {
502516 $ askRevisionUrl = api_get_self ().'? ' .api_get_cidreq ().'& ' .http_build_query ([
503- 'forum ' => $ forumId ,
504- 'thread ' => $ threadId ,
505- 'action ' => 'ask_revision ' ,
506- 'post_id ' => $ post ['post_id ' ],
507- ]);
517+ 'forum ' => $ forumId ,
518+ 'thread ' => $ threadId ,
519+ 'action ' => 'ask_revision ' ,
520+ 'post_id ' => $ post ['post_id ' ],
521+ ]);
508522 $ askForRevision = Display::url (
509523 Display::getMdiIcon ('history ' , 'ch-tool-icon ' , null , ICON_SIZE_SMALL , get_lang ('Ask for revision ' )),
510524 $ askRevisionUrl ,
@@ -566,11 +580,11 @@ function setFocus() {
566580 $ reportButton = '' ;
567581 if ($ allowReport ) {
568582 $ reportUrl = api_get_self ().'? ' .api_get_cidreq ().'& ' .http_build_query ([
569- 'forum ' => $ forumId ,
570- 'thread ' => $ threadId ,
571- 'action ' => 'report ' ,
572- 'post ' => $ post ['post_id ' ],
573- ]);
583+ 'forum ' => $ forumId ,
584+ 'thread ' => $ threadId ,
585+ 'action ' => 'report ' ,
586+ 'post ' => $ post ['post_id ' ],
587+ ]);
574588 $ reportButton = Display::url (
575589 Display::getMdiIcon (ToolIcon::MESSAGE , 'ch-tool-icon ' , null , ICON_SIZE_SMALL , get_lang ('Report ' )),
576590 $ reportUrl ,
@@ -597,23 +611,23 @@ function setFocus() {
597611 $ waitingValidation = '' ;
598612
599613 if (!$ isOp ) {
600- if (($ current_forum_category && 0 == $ current_forum_category ->getLocked ()) &&
601- 0 == $ forumEntity ->getLocked () && 0 == $ threadEntity ->getLocked () || api_is_allowed_to_edit (false , true )
614+ if (($ current_forum_category && 0 == $ current_forum_category ->getLocked ())
615+ && 0 == $ forumEntity ->getLocked () && 0 == $ threadEntity ->getLocked () || api_is_allowed_to_edit (false , true )
602616 ) {
603617 if ($ userId || (1 == $ forumEntity ->getAllowAnonymous () && !$ userId )) {
604618 if (!api_is_anonymous () && api_is_allowed_to_session_edit (false , true )) {
605619 $ replyUrl = 'reply.php? ' .api_get_cidreq ().'& ' .http_build_query ([
606- 'forum ' => $ forumId ,
607- 'thread ' => $ threadId ,
608- 'post ' => $ post ['post_id ' ],
609- 'action ' => 'replymessage ' ,
610- ]);
620+ 'forum ' => $ forumId ,
621+ 'thread ' => $ threadId ,
622+ 'post ' => $ post ['post_id ' ],
623+ 'action ' => 'replymessage ' ,
624+ ]);
611625 $ quoteUrl = 'reply.php? ' .api_get_cidreq ().'& ' .http_build_query ([
612- 'forum ' => $ forumId ,
613- 'thread ' => $ threadId ,
614- 'post ' => $ post ['post_id ' ],
615- 'action ' => 'quote ' ,
616- ]);
626+ 'forum ' => $ forumId ,
627+ 'thread ' => $ threadId ,
628+ 'post ' => $ post ['post_id ' ],
629+ 'action ' => 'quote ' ,
630+ ]);
617631
618632 // students only get reply/quote on validated posts
619633 if ($ forumEntity ->isModerated () && !api_is_allowed_to_edit (false , true )) {
@@ -695,16 +709,17 @@ function setFocus() {
695709 $ attachments = $ postEntity ->getAttachments ();
696710 if ($ attachments ) {
697711 $ repoAttach = Container::getForumAttachmentRepository ();
712+
698713 /** @var CForumAttachment $attachment */
699714 foreach ($ attachments as $ attachment ) {
700715 $ post ['post_attachments ' ] .= Display::getMdiIcon ('paperclip ' , 'ch-tool-icon ' , '' , ICON_SIZE_SMALL );
701716 $ url = $ repoAttach ->getResourceFileDownloadUrl ($ attachment ).'? ' .api_get_cidreq ();
702717 $ post ['post_attachments ' ] .= Display::url ($ attachment ->getFilename (), $ url );
703718 $ post ['post_attachments ' ] .= '<span class="forum_attach_comment"> ' .$ attachment ->getComment ().'</span> ' ;
704- if ((1 == $ forumEntity ->getAllowEdit () && $ post ['user_id ' ] == $ userId ) ||
705- (api_is_allowed_to_edit (false , true ) && !( api_is_session_general_coach () ))
719+ if ((1 == $ forumEntity ->getAllowEdit () && $ post ['user_id ' ] == $ userId )
720+ || (api_is_allowed_to_edit (false , true ) && !api_is_session_general_coach ())
706721 ) {
707- $ post ['post_attachments ' ] .= ' <a href=" ' .api_get_self ().'? ' .api_get_cidreq ().'&action=delete_attach&id_attach= ' .$ attachment ->getIid ().'&forum= ' .$ forumId .'&thread= ' .$ threadId .'&post= ' .$ post ['post_id ' ].'" onclick="if(!confirm( \'' .addslashes (api_htmlentities (get_lang ('Please confirm your choice ' ), ENT_QUOTES )).'\')) return false;"> ' .Display::getMdiIcon ('delete ' , 'ch-tool-icon ' , null , ICON_SIZE_SMALL , get_lang ('Delete ' )).'</a><br /> ' ;
722+ $ post ['post_attachments ' ] .= ' <a href=" ' .api_get_self ().'? ' .api_get_cidreq ().'&action=delete_attach&id_attach= ' .$ attachment ->getIid ().'&forum= ' .$ forumId .'&thread= ' .$ threadId .'&post= ' .$ post ['post_id ' ].'" onclick="if(!confirm( \'' .addslashes (api_htmlentities (get_lang ('Please confirm your choice ' ), \ ENT_QUOTES )).'\')) return false;"> ' .Display::getMdiIcon ('delete ' , 'ch-tool-icon ' , null , ICON_SIZE_SMALL , get_lang ('Delete ' )).'</a><br /> ' ;
708723 }
709724 }
710725 }
@@ -717,7 +732,7 @@ function setFocus() {
717732 $ buttonQuote ,
718733 $ waitingValidation ,
719734 ], static function ($ html ) {
720- return !empty ($ html ) && trim ( $ html ) !== '' ;
735+ return !empty ($ html ) && '' !== trim ( $ html ) ;
721736 });
722737
723738 // Compose bottom button row
@@ -735,16 +750,16 @@ function setFocus() {
735750
736751$ formToString = '' ;
737752$ showForm = true ;
738- if (!api_is_allowed_to_edit (false , true ) &&
739- (($ current_forum_category && 0 == !$ current_forum_category ->isVisible ($ courseEntity )) || !$ forumEntity ->isVisible ($ courseEntity ))
753+ if (!api_is_allowed_to_edit (false , true )
754+ && (($ current_forum_category && 0 == !$ current_forum_category ->isVisible ($ courseEntity )) || !$ forumEntity ->isVisible ($ courseEntity ))
740755) {
741756 $ showForm = false ;
742757}
743758
744- if (!api_is_allowed_to_edit (false , true ) &&
745- (
746- ($ current_forum_category && 0 != $ current_forum_category ->getLocked ()) ||
747- 0 != $ forumEntity ->getLocked () || 0 != $ threadEntity ->getLocked ()
759+ if (!api_is_allowed_to_edit (false , true )
760+ && (
761+ ($ current_forum_category && 0 != $ current_forum_category ->getLocked ())
762+ || 0 != $ forumEntity ->getLocked () || 0 != $ threadEntity ->getLocked ()
748763 )
749764) {
750765 $ showForm = false ;
0 commit comments