@@ -178,7 +178,7 @@ private function package($zip_path)
178
178
throw new \Exception ($ this ->language ->lang ('CLI_EXTENSION_LANGUAGE_FILE_NOT_FOUND ' , $ zip_path ));
179
179
}
180
180
181
- // These are the language directories (and license) we want to extract from phpBB in order to form British English
181
+ // These are the language directories (and license) we want to extract from phpBB to build British English
182
182
$ language_directories = [
183
183
'docs/LICENSE.txt ' ,
184
184
'ext/phpbb/viglink/language/en ' ,
@@ -226,23 +226,32 @@ private function package($zip_path)
226
226
*/
227
227
private function add_to_zip (ZipArchive $ source_zip , ZipArchive $ dest_zip , $ save_version , $ source_path )
228
228
{
229
- for ($ i = 0 ; $ i < $ source_zip ->numFiles ; $ i ++)
229
+ $ prefix_length = strlen ('phpBB3/ ' );
230
+
231
+ for ($ i = 0 , $ n = $ source_zip ->numFiles ; $ i < $ n ; $ i ++)
230
232
{
231
233
$ stat = $ source_zip ->statIndex ($ i );
232
- if (str_starts_with ($ stat ['name ' ], $ source_path ))
234
+ $ entry_name = $ stat ['name ' ];
235
+
236
+ if (!str_starts_with ($ entry_name , $ source_path ))
237
+ {
238
+ continue ;
239
+ }
240
+
241
+ $ relative_path = substr ($ entry_name , $ prefix_length );
242
+ $ dest_path = $ save_version . '/ ' . $ relative_path ;
243
+
244
+ // Check if it's a directory (size is 0, and the name ends with '/')
245
+ if ($ stat ['size ' ] === 0 && str_ends_with ($ entry_name , '/ ' ))
246
+ {
247
+ $ dest_zip ->addEmptyDir ($ dest_path );
248
+ continue ;
249
+ }
250
+
251
+ $ file_contents = $ source_zip ->getFromName ($ entry_name );
252
+ if ($ file_contents !== false )
233
253
{
234
- if ($ stat ['size ' ] <= 0 && strpos ($ stat ['name ' ], '/ ' , strlen ($ source_path )))
235
- {
236
- $ dest_zip ->addEmptyDir ($ save_version . '/ ' . substr ($ stat ['name ' ], strlen ('phpBB3/ ' )));
237
- continue ;
238
- }
239
-
240
- $ file_contents = $ source_zip ->getFromName ($ stat ['name ' ]);
241
- if ($ file_contents !== false )
242
- {
243
- $ local_path = $ save_version . '/ ' . substr ($ stat ['name ' ], strlen ('phpBB3/ ' ));
244
- $ dest_zip ->addFromString ($ local_path , $ file_contents );
245
- }
254
+ $ dest_zip ->addFromString ($ dest_path , $ file_contents );
246
255
}
247
256
}
248
257
}
0 commit comments