4040final class ExportController extends AbstractController
4141{
4242 /**
43- * @throws Exception
4443 * @throws \Exception
4544 */
4645 #[Route(path: 'admin/api/export/file ' , name: 'admin.api.export.file ' , methods: ['GET ' ])]
4746 public function exportFile (Request $ request ): void
4847 {
4948 $ this ->userHasPermission (PermissionType::EXPORT );
5049
51- $ categoryId = (int ) Filter::filterVar ($ request ->attributes ->get ('categoryId ' ), FILTER_VALIDATE_INT );
52- $ downwards = Filter::filterVar ($ request ->attributes ->get ('downwards ' ), FILTER_VALIDATE_BOOLEAN , false );
53- $ inlineDisposition = Filter::filterVar ($ request ->attributes ->get ('disposition ' ), FILTER_SANITIZE_SPECIAL_CHARS );
54- $ type = Filter::filterVar ($ request ->attributes ->get ('export-type ' ), FILTER_SANITIZE_SPECIAL_CHARS , 'none ' );
50+ $ categoryId = (int ) Filter::filterVar ($ request ->request ->get ('categoryId ' ), FILTER_VALIDATE_INT );
51+ $ downwards = Filter::filterVar ($ request ->request ->get ('downwards ' ), FILTER_VALIDATE_BOOLEAN , false );
52+ $ inlineDisposition = Filter::filterVar ($ request ->request ->get ('disposition ' ), FILTER_SANITIZE_SPECIAL_CHARS );
53+ $ type = Filter::filterVar ($ request ->request ->get ('export-type ' ), FILTER_SANITIZE_SPECIAL_CHARS , 'none ' );
5554
5655 $ faq = $ this ->container ->get (id: 'phpmyfaq.faq ' );
5756 $ category = new Category ($ this ->configuration , [], false );
@@ -63,18 +62,17 @@ public function exportFile(Request $request): void
6362
6463 // Stream the file content
6564 $ httpStreamer = new HttpStreamer ($ type , $ content );
66- if ('inline ' === $ inlineDisposition ) {
67- $ httpStreamer ->send (HeaderUtils::DISPOSITION_INLINE );
68- } else {
69- $ httpStreamer ->send (HeaderUtils::DISPOSITION_ATTACHMENT );
70- }
65+ $ disposition = 'inline ' === $ inlineDisposition
66+ ? HeaderUtils::DISPOSITION_INLINE
67+ : HeaderUtils::DISPOSITION_ATTACHMENT ;
68+ $ httpStreamer ->send ($ disposition );
7169 } catch (Exception |JsonException |CommonMarkException $ e ) {
7270 echo $ e ->getMessage ();
7371 }
7472 }
7573
7674 /**
77- * @throws Exception| \Exception
75+ * @throws \Exception
7876 */
7977 #[Route(path: 'admin/api/export/report ' , name: 'admin.api.export.report ' , methods: ['POST ' ])]
8078 public function exportReport (Request $ request ): Response
@@ -143,18 +141,16 @@ public function exportReport(Request $request): Response
143141 foreach ($ report ->getReportingData () as $ reportData ) {
144142 $ i = $ reportData ['faq_id ' ];
145143 if (isset ($ data ->category , $ reportData ['category_name ' ])) {
144+ $ text [$ i ][] = Report::sanitize ($ report ->convertEncoding ($ reportData ['category_name ' ]));
146145 if (0 !== $ reportData ['category_parent ' ]) {
147146 $ text [$ i ][] = Report::sanitize ($ reportData ['category_parent ' ]);
148- } else {
149- $ text [$ i ][] = Report::sanitize ($ report ->convertEncoding ($ reportData ['category_name ' ]));
150147 }
151148 }
152149
153150 if (isset ($ data ->sub_category )) {
154- if (0 != $ reportData ['category_parent ' ]) {
151+ $ text [$ i ][] = 'n/a ' ;
152+ if (0 !== $ reportData ['category_parent ' ]) {
155153 $ text [$ i ][] = Report::sanitize ($ report ->convertEncoding ($ reportData ['category_name ' ]));
156- } else {
157- $ text [$ i ][] = 'n/a ' ;
158154 }
159155 }
160156
@@ -186,10 +182,9 @@ public function exportReport(Request $request): Response
186182 $ text [$ i ][] = Report::sanitize ($ report ->convertEncoding ($ reportData ['faq_org_author ' ]));
187183 }
188184
185+ $ text [$ i ][] = '' ;
189186 if (isset ($ data ->last_modified_person , $ reportData ['faq_last_author ' ])) {
190187 $ text [$ i ][] = Report::sanitize ($ report ->convertEncoding ($ reportData ['faq_last_author ' ]));
191- } else {
192- $ text [$ i ][] = '' ;
193188 }
194189
195190 if (isset ($ data ->url )) {
@@ -207,9 +202,9 @@ public function exportReport(Request $request): Response
207202 }
208203 }
209204
210- $ handle = fopen ('php://temp ' , 'r+ ' );
205+ $ handle = fopen ('php://temp ' , mode: 'r+ ' );
211206 foreach ($ text as $ row ) {
212- fputcsv ($ handle , $ row , ', ' , '" ' , '\\' , PHP_EOL );
207+ fputcsv ($ handle , fields: $ row , separator: ', ' , enclosure: '" ' , escape: '\\' , eol: PHP_EOL );
213208 }
214209
215210 rewind ($ handle );
0 commit comments