2929use SMF \ItemList ;
3030use SMF \Lang ;
3131use SMF \Menu ;
32+ use SMF \ProvidesSubActionInterface ;
33+ use SMF \ProvidesSubActionTrait ;
3234use SMF \Sapi ;
3335use SMF \SecurityToken ;
3436use SMF \Theme ;
4143/**
4244 * Maintains and manages attachments and avatars.
4345 */
44- class Attachments implements ActionInterface
46+ class Attachments implements ActionInterface, ProvidesSubActionInterface
4547{
4648 use ActionTrait;
47-
49+ use ProvidesSubActionTrait;
4850 use BackwardCompatibility;
4951
50- /*******************
51- * Public properties
52- *******************/
53-
54- /**
55- * @var string
56- *
57- * The requested sub-action.
58- * This should be set by the constructor.
59- */
60- public string $ subaction = 'browse ' ;
61-
62- /**************************
63- * Public static properties
64- **************************/
65-
66- /**
67- * @var array
68- *
69- * Available sub-actions.
70- */
71- public static array $ subactions = [
72- 'attachments ' => 'attachmentSettings ' ,
73- 'avatars ' => 'avatarSettings ' ,
74- 'browse ' => 'browse ' ,
75- 'maintenance ' => 'maintain ' ,
76- 'remove ' => 'remove ' ,
77- 'byage ' => 'removeByAge ' ,
78- 'bysize ' => 'removeBySize ' ,
79- 'removeall ' => 'removeAll ' ,
80- 'repair ' => 'repair ' ,
81- 'attachpaths ' => 'paths ' ,
82- 'transfer ' => 'transfer ' ,
83- ];
84-
8552 /****************
8653 * Public methods
8754 ****************/
@@ -91,11 +58,9 @@ class Attachments implements ActionInterface
9158 */
9259 public function execute (): void
9360 {
94- $ call = method_exists ( $ this , self :: $ subactions [ $ this ->subaction ]) ? [ $ this , self :: $ subactions [ $ this -> subaction ]] : Utils:: getCallable ( self :: $ subactions [ $ this -> subaction ]);
61+ IntegrationHook:: call ( ' integrate_manage_attachments ' , [& $ this ->sub_actions ]);
9562
96- if (!empty ($ call )) {
97- call_user_func ($ call );
98- }
63+ $ this ->callSubAction ($ _REQUEST ['sa ' ] ?? null );
9964 }
10065
10166 /**
@@ -2572,6 +2537,19 @@ public static function attachDirStatus(string $dir, int $expected_files): array
25722537 */
25732538 protected function __construct ()
25742539 {
2540+ $ this ->setDefaultSubAction ('browse ' );
2541+ $ this ->addSubAction ('attachments ' , [$ this , 'attachmentSettings ' ]);
2542+ $ this ->addSubAction ('avatars ' , [$ this , 'avatarSettings ' ]);
2543+ $ this ->addSubAction ('browse ' , [$ this , 'browse ' ]);
2544+ $ this ->addSubAction ('maintenance ' , [$ this , 'maintain ' ]);
2545+ $ this ->addSubAction ('remove ' , [$ this , 'remove ' ]);
2546+ $ this ->addSubAction ('byage ' , [$ this , 'removeByAge ' ]);
2547+ $ this ->addSubAction ('bysize ' , [$ this , 'removeBySize ' ]);
2548+ $ this ->addSubAction ('removeall ' , [$ this , 'removeAll ' ]);
2549+ $ this ->addSubAction ('repair ' , [$ this , 'repair ' ]);
2550+ $ this ->addSubAction ('attachpaths ' , [$ this , 'paths ' ]);
2551+ $ this ->addSubAction ('transfer ' , [$ this , 'transfer ' ]);
2552+
25752553 // You have to be able to moderate the forum to do this.
25762554 User::$ me ->isAllowedTo ('manage_attachments ' );
25772555
@@ -2585,14 +2563,6 @@ protected function __construct()
25852563 'description ' => Lang::$ txt ['attachments_desc ' ],
25862564 ];
25872565
2588- IntegrationHook::call ('integrate_manage_attachments ' , [&self ::$ subactions ]);
2589-
2590- if (!empty ($ _REQUEST ['sa ' ]) && isset (self ::$ subactions [strtolower ($ _REQUEST ['sa ' ])])) {
2591- $ this ->subaction = strtolower ($ _REQUEST ['sa ' ]);
2592- }
2593-
2594- Utils::$ context ['sub_action ' ] = &$ this ->subaction ;
2595-
25962566 // Default page title is good.
25972567 Utils::$ context ['page_title ' ] = Lang::$ txt ['attachments_avatars ' ];
25982568 }
0 commit comments