@@ -410,21 +410,17 @@ function updateRolePermissions($roleType, $roles) {
410410 * ** 'param': URL parameter associated with the filter.
411411 * ** 'value': A value for the URL parameter.
412412 * @param string $extraClasses any extra classes you add to the drop down
413- * @param string|null $default The default label for when no filter is active. If `null`, the default label is "All".
413+ * @param string|null $default The default label for when no filter is active. If `null`, the default label is not added
414414 * @param string|null $defaultURL URL override to return to the default, unfiltered state.
415415 * @param string $label Text for the label to attach to the cont
416416 * @return string
417417 */
418418 function sortsDropDown ($ baseUrl , array $ filters = [], $ extraClasses = '' , $ default = null , $ defaultUrl = null , $ label = 'Sort ' ) {
419- if ($ default === null ) {
420- $ default = t ('All ' );
421- }
422-
423419 $ links = [];
424420 $ active = paramPreference (
425421 'sort ' ,
426422 'CategorySort ' ,
427- null ,//'Vanilla.SaveCategorySortPreference',
423+ null ,
428424 null ,
429425 false
430426 );
@@ -462,12 +458,15 @@ function sortsDropDown($baseUrl, array $filters = [], $extraClasses = '', $defau
462458 $ links [] = $ link ;
463459 }
464460
465- // Add the default link to the top of the list.
466- array_unshift ($ links , [
467- 'active ' => $ active === null ,
468- 'name ' => $ default ,
469- 'url ' => $ defaultUrl ?: $ baseUrl
470- ]);
461+ if ($ default !== null ) {
462+ $ default = t ('All ' );
463+ // Add the default link to the top of the list.
464+ array_unshift ($ links , [
465+ 'active ' => $ active === null ,
466+ 'name ' => $ default ,
467+ 'url ' => $ defaultUrl ?: $ baseUrl
468+ ]);
469+ }
471470
472471 // Generate the markup for the drop down menu.
473472 $ output = linkDropDown ($ links , 'selectBox-following ' . trim ($ extraClasses ), t ($ label ) . ': ' );
@@ -487,7 +486,8 @@ function categorySorts($extraClasses = '') {
487486 return ;
488487 }
489488
490- $ baseUrl = Gdn::request ()->path ();
489+ $ baseUrl = Gdn::request ()->getFullPath ();
490+
491491 $ transientKey = Gdn::session ()->transientKey ();
492492 $ filters = [
493493 [
@@ -520,7 +520,7 @@ function categorySorts($extraClasses = '') {
520520 $ baseUrl ,
521521 $ filters ,
522522 $ extraClasses ,
523- t ( ' All ' ) ,
523+ null ,
524524 $ defaultUrl ,
525525 'Sort '
526526 );
@@ -539,7 +539,7 @@ function discussionSorts($extraClasses = '') {
539539 return ;
540540 }
541541
542- $ baseUrl = Gdn::request ()->path ();
542+ $ baseUrl = Gdn::request ()->getFullPath ();
543543 $ transientKey = Gdn::session ()->transientKey ();
544544
545545 $ filters = [
@@ -560,7 +560,7 @@ function discussionSorts($extraClasses = '') {
560560
561561 $ defaultParams = ['save ' => 1 , 'TransientKey ' => $ transientKey ];
562562 if (Gdn::request ()->get ('sort ' )) {
563- $ defaultParams ['sort ' ] = Gdn:: request ()-> get ( ' sort ' ) ;
563+ $ defaultParams ['sort ' ] = '' ;
564564 }
565565
566566 if (!empty ($ defaultParams )) {
@@ -573,11 +573,204 @@ function discussionSorts($extraClasses = '') {
573573 $ baseUrl ,
574574 $ filters ,
575575 $ extraClasses ,
576- t ( ' All ' ) ,
576+ null ,
577577 $ defaultUrl ,
578578 'Sort '
579579 );
580580 }
581581}
582582
583+ if (!function_exists ('discussionFilters ' )) {
584+ /**
585+ *
586+ * FIX: https://github.com/topcoder-platform/forums/issues/226
587+ * The source is package/library/core/functions.render.php
588+ * Returns discussions filtering.
589+ *
590+ * @param string $extraClasses any extra classes you add to the drop down
591+ * @return string
592+ */
593+ function discussionFilters ($ extraClasses = '' ) {
594+ if (!Gdn::session ()->isValid ()) {
595+ return ;
596+ }
597+
598+ $ baseUrl = Gdn::request ()->getFullPath ();
599+ $ transientKey = Gdn::session ()->transientKey ();
600+ $ filters = [
601+ [
602+ 'name ' => t ('All ' ),
603+ 'param ' => 'followed ' ,
604+ 'value ' => 0 ,
605+ 'extra ' => ['save ' => 1 , 'TransientKey ' => $ transientKey ]
606+ ],
607+ [
608+ 'name ' => t ('Following ' ),
609+ 'param ' => 'followed ' ,
610+ 'value ' => 1 ,
611+ 'extra ' => ['save ' => 1 , 'TransientKey ' => $ transientKey ]
612+ ]
613+ ];
614+
615+ $ defaultParams = ['save ' => 1 , 'TransientKey ' => $ transientKey ];
616+ if (Gdn::request ()->get ('followed ' )) {
617+ $ defaultParams ['followed ' ] = '' ;
618+ }
619+
620+ if (!empty ($ defaultParams )) {
621+ $ defaultUrl = $ baseUrl .'? ' .http_build_query ($ defaultParams );
622+ } else {
623+ $ defaultUrl = $ baseUrl ;
624+ }
625+
626+ return filtersDropDown (
627+ $ baseUrl ,
628+ $ filters ,
629+ $ extraClasses ,
630+ null ,
631+ $ defaultUrl ,
632+ 'View '
633+ );
634+ }
635+ }
636+
637+ if (!function_exists ('categoryFilters ' )) {
638+ /**
639+ *
640+ * FIX: https://github.com/topcoder-platform/forums/issues/226
641+ * The source is package/library/core/functions.render.php
642+ *
643+ * Returns category filtering.
644+ *
645+ * @param string $extraClasses any extra classes you add to the drop down
646+ * @return string
647+ */
648+ function categoryFilters ($ extraClasses = '' ) {
649+ if (!Gdn::session ()->isValid ()) {
650+ return ;
651+ }
583652
653+ $ baseUrl = Gdn::request ()->getFullPath ();
654+ $ transientKey = Gdn::session ()->transientKey ();
655+ $ filters = [
656+ [
657+ 'name ' => t ('All ' ),
658+ 'param ' => 'followed ' ,
659+ 'value ' => 0 ,
660+ 'extra ' => ['save ' => 1 , 'TransientKey ' => $ transientKey ]
661+ ],
662+
663+ [
664+ 'name ' => t ('Following ' ),
665+ 'param ' => 'followed ' ,
666+ 'value ' => 1 ,
667+ 'extra ' => ['save ' => 1 , 'TransientKey ' => $ transientKey ]
668+ ]
669+ ];
670+
671+ $ defaultParams = ['save ' => 1 , 'TransientKey ' => $ transientKey ];
672+ if (Gdn::request ()->get ('followed ' )) {
673+ $ defaultParams ['followed ' ] = '' ;
674+ }
675+
676+ if (!empty ($ defaultParams )) {
677+ $ defaultUrl = $ baseUrl .'? ' .http_build_query ($ defaultParams );
678+ } else {
679+ $ defaultUrl = $ baseUrl ;
680+ }
681+
682+ return filtersDropDown (
683+ $ baseUrl ,
684+ $ filters ,
685+ $ extraClasses ,
686+ null ,
687+ $ defaultUrl ,
688+ 'View '
689+ );
690+ }
691+ }
692+
693+ if (!function_exists ('filtersDropDown ' )) {
694+ /**
695+ * FIX: https://github.com/topcoder-platform/forums/issues/226
696+ * The source is package/library/core/functions.render.php
697+ *
698+ * Returns a filtering drop-down menu.
699+ *
700+ * @param string $baseUrl Target URL with no query string applied.
701+ * @param array $filters A multidimensional array of rows with the following properties:
702+ * ** 'name': Friendly name for the filter.
703+ * ** 'param': URL parameter associated with the filter.
704+ * ** 'value': A value for the URL parameter.
705+ * @param string $extraClasses any extra classes you add to the drop down
706+ * @param string|null $default The default label for when no filter is active. If `null`, the default label is "All".
707+ * @param string|null $defaultURL URL override to return to the default, unfiltered state.
708+ * @param string $label Text for the label to attach to the cont
709+ * @return string
710+ */
711+ function filtersDropDown ($ baseUrl , array $ filters = [], $ extraClasses = '' , $ default = null , $ defaultUrl = null , $ label = 'View ' ) {
712+
713+ $ output = '' ;
714+
715+ if (c ('Vanilla.EnableCategoryFollowing ' )) {
716+ $ links = [];
717+ $ active = paramPreference (
718+ 'followed ' ,
719+ 'FollowedCategories ' ,
720+ 'Vanilla.SaveFollowingPreference ' ,
721+ null ,
722+ false
723+ );
724+
725+ // Translate filters into links.
726+ foreach ($ filters as $ filter ) {
727+ // Make sure we have the bare minimum: a label and a URL parameter.
728+ if (!array_key_exists ('name ' , $ filter )) {
729+ throw new InvalidArgumentException ('Filter does not have a name field. ' );
730+ }
731+ if (!array_key_exists ('param ' , $ filter )) {
732+ throw new InvalidArgumentException ('Filter does not have a param field. ' );
733+ }
734+
735+ // Prepare for consumption by linkDropDown.
736+ $ value = $ filter ['value ' ];
737+ $ query = [$ filter ['param ' ] => $ value ];
738+ if (array_key_exists ('extra ' , $ filter ) && is_array ($ filter ['extra ' ])) {
739+ $ query += $ filter ['extra ' ];
740+ }
741+ $ url = url ($ baseUrl .'? ' .http_build_query ($ query ));
742+ $ link = [
743+ 'name ' => $ filter ['name ' ],
744+ 'url ' => $ url
745+ ];
746+
747+ // If we don't already have an active link, and this parameter and value match, this is the active link.
748+ if ($ active === null && Gdn::request ()->get ($ filter ['param ' ]) == $ filter ['value ' ]) {
749+ $ active = $ filter ['value ' ];
750+ $ link ['active ' ] = true ;
751+ } else if ($ active == $ filter ['value ' ]){
752+ $ link ['active ' ] = true ;
753+ $ active = $ filter ['value ' ];
754+ }
755+
756+ // Queue up another filter link.
757+ $ links [] = $ link ;
758+ }
759+
760+ if ($ default !== null ) {
761+ $ default = t ('All ' );
762+
763+ // Add the default link to the top of the list.
764+ array_unshift ($ links , [
765+ 'active ' => $ active === null ,
766+ 'name ' => $ default ,
767+ 'url ' => $ defaultUrl ?: $ baseUrl
768+ ]);
769+ }
770+ // Generate the markup for the drop down menu.
771+ $ output = linkDropDown ($ links , 'selectBox-following ' .trim ($ extraClasses ), t ($ label ).': ' );
772+ }
773+
774+ return $ output ;
775+ }
776+ }
0 commit comments