2626use phpMyFAQ \Controller \AbstractController ;
2727use phpMyFAQ \Core \Exception ;
2828use phpMyFAQ \Enums \PermissionType ;
29+ use phpMyFAQ \Filter ;
2930use phpMyFAQ \Session \Token ;
3031use phpMyFAQ \Translation ;
3132use phpMyFAQ \User \CurrentUser ;
@@ -44,10 +45,8 @@ public function delete(Request $request): JsonResponse
4445 {
4546 $ this ->userHasPermission (PermissionType::CATEGORY_DELETE );
4647
47- $ configuration = Configuration::getConfigurationInstance ();
48- $ currentUser = CurrentUser::getCurrentUser ($ configuration );
48+ $ currentUser = CurrentUser::getCurrentUser ($ this ->configuration );
4949
50- $ jsonResponse = new JsonResponse ();
5150 $ data = json_decode ($ request ->getContent ());
5251
5352 if (!Token::getInstance ()->verifyToken ('category ' , $ data ->csrfToken )) {
@@ -56,19 +55,19 @@ public function delete(Request $request): JsonResponse
5655
5756 [ $ currentAdminUser , $ currentAdminGroups ] = CurrentUser::getCurrentUserGroupId ($ currentUser );
5857
59- $ category = new Category ($ configuration , [], false );
58+ $ category = new Category ($ this -> configuration , [], false );
6059 $ category ->setUser ($ currentAdminUser );
6160 $ category ->setGroups ($ currentAdminGroups );
6261
63- $ categoryRelation = new CategoryRelation ($ configuration , $ category );
62+ $ categoryRelation = new CategoryRelation ($ this -> configuration , $ category );
6463
65- $ categoryImage = new CategoryImage ($ configuration );
64+ $ categoryImage = new CategoryImage ($ this -> configuration );
6665 $ categoryImage ->setFileName ($ category ->getCategoryData ($ data ->categoryId )->getImage ());
6766
68- $ categoryOrder = new CategoryOrder ($ configuration );
67+ $ categoryOrder = new CategoryOrder ($ this -> configuration );
6968 $ categoryOrder ->remove ($ data ->categoryId );
7069
71- $ categoryPermission = new CategoryPermission ($ configuration );
70+ $ categoryPermission = new CategoryPermission ($ this -> configuration );
7271
7372 if (
7473 (
@@ -88,7 +87,7 @@ public function delete(Request $request): JsonResponse
8887 return $ this ->json (['success ' => Translation::get ('ad_categ_deleted ' )], Response::HTTP_OK );
8988 } else {
9089 return $ this ->json (
91- ['error ' => Translation::get ('ad_adus_dberr ' ) . $ configuration ->getDb ()->error ()],
90+ ['error ' => Translation::get ('ad_adus_dberr ' ) . $ this -> configuration ->getDb ()->error ()],
9291 Response::HTTP_INTERNAL_SERVER_ERROR
9392 );
9493 }
@@ -97,12 +96,12 @@ public function delete(Request $request): JsonResponse
9796 /**
9897 * @throws Exception
9998 */
100- #[Route('admin/api/category/permissions ' )]
99+ #[Route('admin/api/category/permissions ' , methods: [ ' GET ' ] )]
101100 public function permissions (Request $ request ): JsonResponse
102101 {
103102 $ this ->userIsAuthenticated ();
104103
105- $ categoryPermission = new CategoryPermission (Configuration:: getConfigurationInstance () );
104+ $ categoryPermission = new CategoryPermission ($ this -> configuration );
106105
107106 $ categoryData = $ request ->get ('categories ' );
108107
@@ -112,6 +111,10 @@ public function permissions(Request $request): JsonResponse
112111 $ categories = explode (', ' , (string ) $ categoryData );
113112 }
114113
114+ if (!in_array (true , filter_var_array ($ categories , FILTER_VALIDATE_INT ))) {
115+ return $ this ->json (['error ' => 'Only integer values are valid. ' ], Response::HTTP_BAD_REQUEST );
116+ }
117+
115118 return $ this ->json (
116119 [
117120 'user ' => $ categoryPermission ->get (CategoryPermission::USER , $ categories ),
@@ -129,10 +132,11 @@ public function translations(Request $request): JsonResponse
129132 {
130133 $ this ->userIsAuthenticated ();
131134
132- $ configuration = Configuration::getConfigurationInstance ();
133- $ category = new Category ($ configuration , [], false );
135+ $ category = new Category ($ this ->configuration , [], false );
136+
137+ $ categoryId = Filter::filterVar ($ request ->get ('categoryId ' ), FILTER_VALIDATE_INT );
134138
135- $ translations = $ category ->getCategoryLanguagesTranslated ($ request -> get ( ' categoryId ' ) );
139+ $ translations = $ category ->getCategoryLanguagesTranslated ($ categoryId );
136140
137141 return $ this ->json ($ translations , Response::HTTP_OK );
138142 }
@@ -151,17 +155,16 @@ public function updateOrder(Request $request): JsonResponse
151155 return $ this ->json (['error ' => Translation::get ('err_NotAuth ' )], Response::HTTP_UNAUTHORIZED );
152156 }
153157
154- $ configuration = Configuration::getConfigurationInstance ();
155- $ user = CurrentUser::getCurrentUser ($ configuration );
158+ $ user = CurrentUser::getCurrentUser ($ this ->configuration );
156159
157160 [ $ currentAdminUser , $ currentAdminGroups ] = CurrentUser::getCurrentUserGroupId ($ user );
158161
159- $ categoryOrder = new CategoryOrder ($ configuration );
162+ $ categoryOrder = new CategoryOrder ($ this -> configuration );
160163 $ categoryOrder ->setCategoryTree ($ data ->categoryTree );
161164
162165 $ parentId = $ categoryOrder ->getParentId ($ data ->categoryTree , (int )$ data ->categoryId );
163166
164- $ category = new Category ($ configuration , [], false );
167+ $ category = new Category ($ this -> configuration , [], false );
165168 $ category ->setUser ($ currentAdminUser );
166169 $ category ->setGroups ($ currentAdminGroups );
167170 $ category ->updateParentCategory ($ data ->categoryId , $ parentId );
0 commit comments