@@ -527,30 +527,51 @@ protected function get_document_url($type, $params)
527527 {
528528 $ params = unserialize ($ params , ['allowed_classes ' => false ]);
529529
530+ // Return empty string if params are invalid
531+ if (!is_array ($ params ) || empty ($ params ))
532+ {
533+ return '' ;
534+ }
535+
536+ $ required_params = [];
537+
530538 switch ($ type )
531539 {
532540 case ext::TITANIA_FAQ :
533541 $ controller = 'phpbb.titania.contrib.faq.item ' ;
542+ $ required_params = ['contrib_type ' , 'contrib ' , 'id ' ];
534543 break ;
535544
536545 case ext::TITANIA_QUEUE :
537546 $ controller = 'phpbb.titania.queue.item ' ;
547+ $ required_params = ['id ' ];
538548 break ;
539549
540550 case ext::TITANIA_SUPPORT :
541551 case ext::TITANIA_QUEUE_DISCUSSION :
542552 $ controller = 'phpbb.titania.contrib.support.topic ' ;
553+ $ required_params = ['contrib_type ' , 'contrib ' , 'topic_id ' ];
543554 break ;
544555
545556 case ext::TITANIA_CONTRIB :
546557 $ controller = 'phpbb.titania.contrib ' ;
558+ $ required_params = ['contrib_type ' , 'contrib ' ];
547559 break ;
548560
549561 default :
550562 return '' ;
551563 }
552564
553- return $ this ->helper ->route ($ controller , is_array ($ params ) ? $ params : array ());
565+ // Verify all required parameters are present
566+ foreach ($ required_params as $ required_param )
567+ {
568+ if (!isset ($ params [$ required_param ]) || $ params [$ required_param ] === '' )
569+ {
570+ return '' ;
571+ }
572+ }
573+
574+ return $ this ->helper ->route ($ controller , $ params );
554575 }
555576
556577 /**
@@ -660,12 +681,23 @@ protected function get_posts(array $ids, array $documents, bool $is_sphinx)
660681 while ($ row = $ this ->db ->sql_fetchrow ($ result ))
661682 {
662683 $ id = $ row ['post_type ' ] . '_ ' . ($ is_sphinx ? $ row ['id ' ] + 20000000 : $ row ['id ' ]);
663- $ row ['url ' ] = serialize (array_merge (unserialize ($ row ['url ' ], ['allowed_classes ' => false ]), array (
664- 'topic_id ' => $ row ['topic_id ' ],
665- 'p ' => $ row ['id ' ],
666- '# ' => 'p ' . $ row ['id ' ],
667- )));
668- $ documents [$ id ] = array_merge ($ documents [$ id ], $ row );
684+
685+ // Unserialize existing URL parameters (contains contrib_type and contrib)
686+ $ url_params = unserialize ($ row ['url ' ], ['allowed_classes ' => false ]);
687+
688+ // Only add to documents if we have valid URL params with required fields
689+ if (is_array ($ url_params ) && !empty ($ url_params ))
690+ {
691+ // Add additional parameters for topic/post navigation
692+ $ url_params = array_merge ($ url_params , array (
693+ 'topic_id ' => $ row ['topic_id ' ],
694+ 'p ' => $ row ['id ' ],
695+ '# ' => 'p ' . $ row ['id ' ],
696+ ));
697+
698+ $ row ['url ' ] = serialize ($ url_params );
699+ $ documents [$ id ] = array_merge ($ documents [$ id ], $ row );
700+ }
669701 }
670702 $ this ->db ->sql_freeresult ($ result );
671703
@@ -696,11 +728,19 @@ protected function get_contribs(array $ids, array $documents)
696728 while ($ row = $ this ->db ->sql_fetchrow ($ result ))
697729 {
698730 $ id = ext::TITANIA_CONTRIB . '_ ' . $ row ['id ' ];
699- $ row ['url ' ] = serialize (array (
700- 'contrib_type ' => $ this ->types ->get ($ row ['contrib_type ' ])->url ,
701- 'contrib ' => $ row ['contrib_name_clean ' ],
702- ));
703- $ documents [$ id ] = array_merge ($ documents [$ id ], $ row );
731+
732+ // Get the contrib type object to get the URL-friendly type name
733+ $ contrib_type_obj = $ this ->types ->get ($ row ['contrib_type ' ]);
734+
735+ // Only add URL if we have a valid contrib type
736+ if ($ contrib_type_obj )
737+ {
738+ $ row ['url ' ] = serialize (array (
739+ 'contrib_type ' => $ contrib_type_obj ->url ,
740+ 'contrib ' => $ row ['contrib_name_clean ' ],
741+ ));
742+ $ documents [$ id ] = array_merge ($ documents [$ id ], $ row );
743+ }
704744 }
705745 $ this ->db ->sql_freeresult ($ result );
706746
@@ -734,12 +774,20 @@ protected function get_faqs(array $ids, array $documents, bool $is_sphinx)
734774 while ($ row = $ this ->db ->sql_fetchrow ($ result ))
735775 {
736776 $ id = ext::TITANIA_FAQ . '_ ' . ($ is_sphinx ? $ row ['id ' ] + 10000000 : $ row ['id ' ]);
737- $ row ['url ' ] = serialize (array (
738- 'contrib_type ' => $ this ->types ->get ($ row ['contrib_type ' ])->url ,
739- 'contrib ' => $ row ['contrib_name_clean ' ],
740- 'id ' => $ row ['id ' ],
741- ));
742- $ documents [$ id ] = array_merge ($ documents [$ id ], $ row );
777+
778+ // Get the contrib type object to get the URL-friendly type name
779+ $ contrib_type_obj = $ this ->types ->get ($ row ['contrib_type ' ]);
780+
781+ // Only add URL if we have a valid contrib type
782+ if ($ contrib_type_obj )
783+ {
784+ $ row ['url ' ] = serialize (array (
785+ 'contrib_type ' => $ contrib_type_obj ->url ,
786+ 'contrib ' => $ row ['contrib_name_clean ' ],
787+ 'id ' => $ row ['id ' ],
788+ ));
789+ $ documents [$ id ] = array_merge ($ documents [$ id ], $ row );
790+ }
743791 }
744792 $ this ->db ->sql_freeresult ($ result );
745793
0 commit comments