@@ -122,28 +122,43 @@ public function json(ServerRequestInterface $request): ResponseInterface
122122 $ page = isset ($ params ['page ' ]) ? max (1 , (int )$ params ['page ' ]) : 1 ;
123123 $ perPage = isset ($ params ['per_page ' ]) ? min (100 , max (1 , (int )$ params ['per_page ' ])) : 20 ;
124124 $ offset = ($ page - 1 ) * $ perPage ;
125- $ categorySlug = $ params ['category ' ] ?? null ;
126- $ tagSlug = $ params ['tag ' ] ?? null ;
125+
126+ // Support both single and multiple categories/tags
127+ $ categorySlugs = [];
128+ if (isset ($ params ['category ' ])) {
129+ $ categorySlugs = [$ params ['category ' ]];
130+ } elseif (isset ($ params ['categories ' ])) {
131+ $ categorySlugs = array_filter (explode (', ' , $ params ['categories ' ]));
132+ }
133+
134+ $ tagSlugs = [];
135+ if (isset ($ params ['tag ' ])) {
136+ $ tagSlugs = [$ params ['tag ' ]];
137+ } elseif (isset ($ params ['tags ' ])) {
138+ $ tagSlugs = array_filter (explode (', ' , $ params ['tags ' ]));
139+ }
127140
128141 $ whereConditions = ["fi.is_visible = 1 " ];
129142 $ queryParams = [];
130143
131- if ($ categorySlug ) {
144+ if (!empty ($ categorySlugs )) {
145+ $ placeholders = implode (', ' , array_fill (0 , count ($ categorySlugs ), '%s ' ));
132146 $ whereConditions [] = "EXISTS (
133147 SELECT 1 FROM feed_categories fc
134148 JOIN categories c ON fc.category_id = c.id
135- WHERE fc.feed_id = f.id AND c.slug = %s
149+ WHERE fc.feed_id = f.id AND c.slug IN ( $ placeholders )
136150 ) " ;
137- $ queryParams[] = $ categorySlug ;
151+ $ queryParams = array_merge ( $ queryParams , $ categorySlugs ) ;
138152 }
139153
140- if ($ tagSlug ) {
154+ if (!empty ($ tagSlugs )) {
155+ $ placeholders = implode (', ' , array_fill (0 , count ($ tagSlugs ), '%s ' ));
141156 $ whereConditions [] = "EXISTS (
142157 SELECT 1 FROM feed_tags ft
143158 JOIN tags t ON ft.tag_id = t.id
144- WHERE ft.feed_id = f.id AND t.slug = %s
159+ WHERE ft.feed_id = f.id AND t.slug IN ( $ placeholders )
145160 ) " ;
146- $ queryParams[] = $ tagSlug ;
161+ $ queryParams = array_merge ( $ queryParams , $ tagSlugs ) ;
147162 }
148163
149164 $ whereClause = implode (' AND ' , $ whereConditions );
@@ -203,28 +218,43 @@ public function rss(ServerRequestInterface $request): ResponseInterface
203218 $ page = isset ($ params ['page ' ]) ? max (1 , (int )$ params ['page ' ]) : 1 ;
204219 $ perPage = isset ($ params ['per_page ' ]) ? min (100 , max (1 , (int )$ params ['per_page ' ])) : 20 ;
205220 $ offset = ($ page - 1 ) * $ perPage ;
206- $ categorySlug = $ params ['category ' ] ?? null ;
207- $ tagSlug = $ params ['tag ' ] ?? null ;
221+
222+ // Support both single and multiple categories/tags
223+ $ categorySlugs = [];
224+ if (isset ($ params ['category ' ])) {
225+ $ categorySlugs = [$ params ['category ' ]];
226+ } elseif (isset ($ params ['categories ' ])) {
227+ $ categorySlugs = array_filter (explode (', ' , $ params ['categories ' ]));
228+ }
229+
230+ $ tagSlugs = [];
231+ if (isset ($ params ['tag ' ])) {
232+ $ tagSlugs = [$ params ['tag ' ]];
233+ } elseif (isset ($ params ['tags ' ])) {
234+ $ tagSlugs = array_filter (explode (', ' , $ params ['tags ' ]));
235+ }
208236
209237 $ whereConditions = ["fi.is_visible = 1 " ];
210238 $ queryParams = [];
211239
212- if ($ categorySlug ) {
240+ if (!empty ($ categorySlugs )) {
241+ $ placeholders = implode (', ' , array_fill (0 , count ($ categorySlugs ), '%s ' ));
213242 $ whereConditions [] = "EXISTS (
214243 SELECT 1 FROM feed_categories fc
215244 JOIN categories c ON fc.category_id = c.id
216- WHERE fc.feed_id = f.id AND c.slug = %s
245+ WHERE fc.feed_id = f.id AND c.slug IN ( $ placeholders )
217246 ) " ;
218- $ queryParams[] = $ categorySlug ;
247+ $ queryParams = array_merge ( $ queryParams , $ categorySlugs ) ;
219248 }
220249
221- if ($ tagSlug ) {
250+ if (!empty ($ tagSlugs )) {
251+ $ placeholders = implode (', ' , array_fill (0 , count ($ tagSlugs ), '%s ' ));
222252 $ whereConditions [] = "EXISTS (
223253 SELECT 1 FROM feed_tags ft
224254 JOIN tags t ON ft.tag_id = t.id
225- WHERE ft.feed_id = f.id AND t.slug = %s
255+ WHERE ft.feed_id = f.id AND t.slug IN ( $ placeholders )
226256 ) " ;
227- $ queryParams[] = $ tagSlug ;
257+ $ queryParams = array_merge ( $ queryParams , $ tagSlugs ) ;
228258 }
229259
230260 $ whereClause = implode (' AND ' , $ whereConditions );
@@ -248,6 +278,7 @@ public function rss(ServerRequestInterface $request): ResponseInterface
248278 $ channel ->addChild ('language ' , 'pt-br ' );
249279 $ channel ->addChild ('pubDate ' , date ('r ' ));
250280
281+
251282 foreach ($ items as $ item ) {
252283 $ xmlItem = $ channel ->addChild ('item ' );
253284 $ xmlItem ->addChild ('title ' , htmlspecialchars ($ item ['title ' ]));
@@ -279,4 +310,21 @@ public function rss(ServerRequestInterface $request): ResponseInterface
279310
280311 return new XmlResponse ($ xmlString );
281312 }
313+
314+ public function feedBuilder (ServerRequestInterface $ request ): ResponseInterface
315+ {
316+ // Get all categories with item counts from the cached column
317+ $ categories = DB ::query ("SELECT * FROM categories ORDER BY name " );
318+
319+ // Get all tags with item counts from the cached column
320+ $ tags = DB ::query ("SELECT * FROM tags ORDER BY name " );
321+
322+ $ html = $ this ->templates ->render ('feed-builder ' , [
323+ 'categories ' => $ categories ,
324+ 'tags ' => $ tags ,
325+ 'title ' => 'Construtor de Feed '
326+ ]);
327+
328+ return new HtmlResponse ($ html );
329+ }
282330}
0 commit comments