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;
49+ use ProvidesSubActionTrait;
4750
4851 use BackwardCompatibility;
4952
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-
85- /****************
53+ /**************
8654 * Public methods
8755 ****************/
8856
@@ -91,11 +59,22 @@ class Attachments implements ActionInterface
9159 */
9260 public function execute (): void
9361 {
94- $ call = method_exists ($ this , self ::$ subactions [$ this ->subaction ]) ? [$ this , self ::$ subactions [$ this ->subaction ]] : Utils::getCallable (self ::$ subactions [$ this ->subaction ]);
95-
96- if (!empty ($ call )) {
97- call_user_func ($ call );
98- }
62+ $ this ->setDefaultSubAction ('browse ' );
63+ $ this ->addSubAction ('attachments ' , [$ this , 'attachmentSettings ' ]);
64+ $ this ->addSubAction ('avatars ' , [$ this , 'avatarSettings ' ]);
65+ $ this ->addSubAction ('browse ' , [$ this , 'browse ' ]);
66+ $ this ->addSubAction ('maintenance ' , [$ this , 'maintain ' ]);
67+ $ this ->addSubAction ('remove ' , [$ this , 'remove ' ]);
68+ $ this ->addSubAction ('byage ' , [$ this , 'removeByAge ' ]);
69+ $ this ->addSubAction ('bysize ' , [$ this , 'removeBySize ' ]);
70+ $ this ->addSubAction ('removeall ' , [$ this , 'removeAll ' ]);
71+ $ this ->addSubAction ('repair ' , [$ this , 'repair ' ]);
72+ $ this ->addSubAction ('attachpaths ' , [$ this , 'paths ' ]);
73+ $ this ->addSubAction ('transfer ' , [$ this , 'transfer ' ]);
74+
75+ IntegrationHook::call ('integrate_manage_attachments ' , [&$ this ->sub_actions ]);
76+
77+ $ this ->callSubAction ($ _REQUEST ['sa ' ] ?? null );
9978 }
10079
10180 /**
@@ -2572,7 +2551,7 @@ public static function manageAttachmentSettings(bool $return_config = false): ?a
25722551 }
25732552
25742553 self ::load ();
2575- self ::$ obj ->subaction = 'attachments ' ;
2554+ self ::$ obj ->setDefaultSubAction ( 'attachments ' ) ;
25762555 self ::$ obj ->execute ();
25772556
25782557 return null ;
@@ -2591,7 +2570,7 @@ public static function manageAvatarSettings(bool $return_config = false): ?array
25912570 }
25922571
25932572 self ::load ();
2594- self ::$ obj ->subaction = 'avatars ' ;
2573+ self ::$ obj ->setDefaultSubAction ( 'avatars ' ) ;
25952574 self ::$ obj ->execute ();
25962575
25972576 return null ;
@@ -2619,14 +2598,6 @@ protected function __construct()
26192598 'description ' => Lang::$ txt ['attachments_desc ' ],
26202599 ];
26212600
2622- IntegrationHook::call ('integrate_manage_attachments ' , [&self ::$ subactions ]);
2623-
2624- if (!empty ($ _REQUEST ['sa ' ]) && isset (self ::$ subactions [strtolower ($ _REQUEST ['sa ' ])])) {
2625- $ this ->subaction = strtolower ($ _REQUEST ['sa ' ]);
2626- }
2627-
2628- Utils::$ context ['sub_action ' ] = &$ this ->subaction ;
2629-
26302601 // Default page title is good.
26312602 Utils::$ context ['page_title ' ] = Lang::$ txt ['attachments_avatars ' ];
26322603 }
0 commit comments