@@ -55,6 +55,112 @@ class FileHtaccess extends Controllo
5555 ],
5656 ];
5757
58+ public function getName ()
59+ {
60+ return tr ('File .htaccess di sistema ' );
61+ }
62+
63+ public function getType ($ record )
64+ {
65+ return 'warning ' ;
66+ }
67+
68+ public function getOptions ($ record )
69+ {
70+ return [
71+ [
72+ 'name ' => tr ('Rigenera file ' ),
73+ 'icon ' => 'fa fa-refresh ' ,
74+ 'color ' => 'success ' ,
75+ 'params ' => ['action ' => 'regenerate ' ],
76+ ],
77+ ];
78+ }
79+
80+ public function hasGlobalActions ()
81+ {
82+ return true ;
83+ }
84+
85+ public function getGlobalActions ()
86+ {
87+ $ missing_count = count ($ this ->results );
88+ if ($ missing_count === 0 ) {
89+ return [];
90+ }
91+
92+ return [
93+ [
94+ 'name ' => tr ('Rigenera tutti i file mancanti ' ),
95+ 'icon ' => 'fa fa-refresh ' ,
96+ 'color ' => 'success ' ,
97+ 'params ' => ['action ' => 'regenerate_all ' ],
98+ 'badge ' => $ missing_count .' ' .tr ('file ' ),
99+ ],
100+ ];
101+ }
102+
103+ public function check ()
104+ {
105+ foreach (self ::$ htaccess_config as $ folder => $ config ) {
106+ // Gestione speciale per la directory root
107+ if ($ folder === '' ) {
108+ $ folder_path = base_dir ();
109+ $ htaccess_path = $ folder_path .'/.htaccess ' ;
110+ $ display_path = '.htaccess ' ;
111+ $ display_folder = tr ('directory principale ' );
112+ } else {
113+ $ folder_path = base_dir ().'/ ' .$ folder ;
114+ $ htaccess_path = $ folder_path .'/.htaccess ' ;
115+ $ display_path = $ folder .'/.htaccess ' ;
116+ $ display_folder = '<code> ' .$ folder .'</code> ' ;
117+
118+ // Verifica se la cartella esiste (solo per sottocartelle)
119+ if (!is_dir ($ folder_path )) {
120+ continue ;
121+ }
122+ }
123+
124+ // Verifica se il file .htaccess esiste
125+ if (!file_exists ($ htaccess_path )) {
126+ $ this ->addResult ([
127+ 'id ' => 'htaccess_ ' .($ folder === '' ? 'root ' : $ folder ),
128+ 'folder ' => $ folder ,
129+ 'nome ' => '<strong>.htaccess</strong><br><small class="text-muted"> ' .$ display_path .'</small> ' ,
130+ 'descrizione ' => tr ('File .htaccess mancante nella _FOLDER_ ' , ['_FOLDER_ ' => $ display_folder ]).'<br><small class="text-muted"> ' .$ config ['description ' ].'</small> ' ,
131+ ]);
132+ }
133+ }
134+ }
135+
136+ public function execute ($ record , $ params = [])
137+ {
138+ $ action = $ params ['action ' ] ?? '' ;
139+
140+ if ($ action === 'regenerate ' ) {
141+ return $ this ->regenerateHtaccess ($ record ['folder ' ]);
142+ }
143+
144+ return tr ('Azione non supportata ' );
145+ }
146+
147+ /**
148+ * Rigenera tutti i file .htaccess mancanti.
149+ */
150+ public function solveGlobal ($ params = [])
151+ {
152+ $ action = $ params ['action ' ] ?? '' ;
153+ $ results = [];
154+
155+ if ($ action === 'regenerate_all ' ) {
156+ foreach ($ this ->results as $ record ) {
157+ $ results [$ record ['id ' ]] = $ this ->regenerateHtaccess ($ record ['folder ' ]);
158+ }
159+ }
160+
161+ return $ results ;
162+ }
163+
58164 /**
59165 * Contenuto del file .htaccess principale (root).
60166 */
@@ -162,112 +268,6 @@ protected static function getRootHtaccessContent()
162268HTACCESS;
163269 }
164270
165- public function getName ()
166- {
167- return tr ('File .htaccess di sistema ' );
168- }
169-
170- public function getType ($ record )
171- {
172- return 'warning ' ;
173- }
174-
175- public function getOptions ($ record )
176- {
177- return [
178- [
179- 'name ' => tr ('Rigenera file ' ),
180- 'icon ' => 'fa fa-refresh ' ,
181- 'color ' => 'success ' ,
182- 'params ' => ['action ' => 'regenerate ' ],
183- ],
184- ];
185- }
186-
187- public function hasGlobalActions ()
188- {
189- return true ;
190- }
191-
192- public function getGlobalActions ()
193- {
194- $ missing_count = count ($ this ->results );
195- if ($ missing_count === 0 ) {
196- return [];
197- }
198-
199- return [
200- [
201- 'name ' => tr ('Rigenera tutti i file mancanti ' ),
202- 'icon ' => 'fa fa-refresh ' ,
203- 'color ' => 'success ' ,
204- 'params ' => ['action ' => 'regenerate_all ' ],
205- 'badge ' => $ missing_count .' ' .tr ('file ' ),
206- ],
207- ];
208- }
209-
210- public function check ()
211- {
212- foreach (self ::$ htaccess_config as $ folder => $ config ) {
213- // Gestione speciale per la directory root
214- if ($ folder === '' ) {
215- $ folder_path = base_dir ();
216- $ htaccess_path = $ folder_path .'/.htaccess ' ;
217- $ display_path = '.htaccess ' ;
218- $ display_folder = tr ('directory principale ' );
219- } else {
220- $ folder_path = base_dir ().'/ ' .$ folder ;
221- $ htaccess_path = $ folder_path .'/.htaccess ' ;
222- $ display_path = $ folder .'/.htaccess ' ;
223- $ display_folder = '<code> ' .$ folder .'</code> ' ;
224-
225- // Verifica se la cartella esiste (solo per sottocartelle)
226- if (!is_dir ($ folder_path )) {
227- continue ;
228- }
229- }
230-
231- // Verifica se il file .htaccess esiste
232- if (!file_exists ($ htaccess_path )) {
233- $ this ->addResult ([
234- 'id ' => 'htaccess_ ' .($ folder === '' ? 'root ' : $ folder ),
235- 'folder ' => $ folder ,
236- 'nome ' => '<strong>.htaccess</strong><br><small class="text-muted"> ' .$ display_path .'</small> ' ,
237- 'descrizione ' => tr ('File .htaccess mancante nella _FOLDER_ ' , ['_FOLDER_ ' => $ display_folder ]).'<br><small class="text-muted"> ' .$ config ['description ' ].'</small> ' ,
238- ]);
239- }
240- }
241- }
242-
243- public function execute ($ record , $ params = [])
244- {
245- $ action = $ params ['action ' ] ?? '' ;
246-
247- if ($ action === 'regenerate ' ) {
248- return $ this ->regenerateHtaccess ($ record ['folder ' ]);
249- }
250-
251- return tr ('Azione non supportata ' );
252- }
253-
254- /**
255- * Rigenera tutti i file .htaccess mancanti.
256- */
257- public function solveGlobal ($ params = [])
258- {
259- $ action = $ params ['action ' ] ?? '' ;
260- $ results = [];
261-
262- if ($ action === 'regenerate_all ' ) {
263- foreach ($ this ->results as $ record ) {
264- $ results [$ record ['id ' ]] = $ this ->regenerateHtaccess ($ record ['folder ' ]);
265- }
266- }
267-
268- return $ results ;
269- }
270-
271271 /**
272272 * Rigenera il file .htaccess per una cartella specifica.
273273 */
@@ -309,4 +309,3 @@ protected function regenerateHtaccess($folder)
309309 return tr ('File .htaccess rigenerato con successo nella _FOLDER_ ' , ['_FOLDER_ ' => $ display_folder ]);
310310 }
311311}
312-
0 commit comments