diff --git a/acpcleanup/acp/main_info.php b/acpcleanup/acp/main_info.php index bb5f85eeb..54427c17a 100644 --- a/acpcleanup/acp/main_info.php +++ b/acpcleanup/acp/main_info.php @@ -12,21 +12,29 @@ namespace phpbbgallery\acpcleanup\acp; +/** + * ACP Module Info class + */ class main_info { - function module() + /** + * Returns module information + * + * @return array Module information + */ + public function module(): array { - return array( - 'filename' => 'main_module', - 'title' => 'PHPBB_GALLERY', - 'version' => '1.0.0', - 'modes' => array( - 'cleanup' => array( - 'title' => 'ACP_GALLERY_CLEANUP', - 'auth' => 'acl_a_gallery_cleanup && ext_phpbbgallery/acpcleanup', - 'cat' => array('PHPBB_GALLERY') - ), - ), - ); + return [ + 'filename' => '\phpbbgallery\acpcleanup\acp\main_module', + 'title' => 'PHPBB_GALLERY', + 'version' => '1.0.0', + 'modes' => [ + 'cleanup' => [ + 'title' => 'ACP_GALLERY_CLEANUP', + 'auth' => 'acl_a_gallery_cleanup && ext_phpbbgallery/acpcleanup', + 'cat' => ['PHPBB_GALLERY'], + ], + ], + ]; } } diff --git a/acpcleanup/acp/main_module.php b/acpcleanup/acp/main_module.php index ea16a3e28..c60f95ecb 100644 --- a/acpcleanup/acp/main_module.php +++ b/acpcleanup/acp/main_module.php @@ -14,28 +14,42 @@ class main_module { - var $u_action; + public string $u_action; - function main($id, $mode) + public function main(string $id, string $mode): void { - global $auth, $cache, $config, $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_ext_gallery; + global $auth, $cache, $config, $db, $template, $request, $user, $phpEx, $phpbb_root_path, $phpbb_ext_gallery; $user->add_lang_ext('phpbbgallery/core', array('gallery_acp', 'gallery')); - //$user->add_lang_ext('phpbbgallery/acpcleanup', 'cleanup'); $this->tpl_name = 'gallery_cleanup'; + add_form_key('acp_gallery'); + $submit = $request->is_set_post('submit'); + + if ($submit && !check_form_key('acp_gallery')) + { + trigger_error($user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); + } + $this->page_title = $user->lang['ACP_GALLERY_CLEANUP']; - $this->cleanup(); + $this->cleanup($submit); } - function cleanup() + /** + * Cleanup gallery files and database entries + * + * @param array $missing_entries Files to clean + * @param bool $move_to_import Whether to move files to import dir + * @return array Messages about cleanup results + * @throws \RuntimeException On file operation errors + */ + public function cleanup(bool $submit = false): void { global $auth, $cache, $db, $template, $user, $phpbb_ext_gallery, $table_prefix, $phpbb_container, $request; - $delete = (isset($_POST['delete'])) ? true : false; - $prune = (isset($_POST['prune'])) ? true : false; - $submit = (isset($_POST['submit'])) ? true : false; + $delete = $request->is_set_post('delete'); + $prune = $request->is_set_post('prune'); $missing_sources = $request->variable('source', array(0)); $missing_entries = $request->variable('entry', array(''), true); diff --git a/acpcleanup/adm/style/gallery_cleanup.html b/acpcleanup/adm/style/gallery_cleanup.html index cc9cf728f..a9f43f608 100644 --- a/acpcleanup/adm/style/gallery_cleanup.html +++ b/acpcleanup/adm/style/gallery_cleanup.html @@ -147,21 +147,10 @@
{S_FORM_TOKEN}
- diff --git a/acpcleanup/composer.json b/acpcleanup/composer.json index 244487263..70589f649 100644 --- a/acpcleanup/composer.json +++ b/acpcleanup/composer.json @@ -26,12 +26,12 @@ } ], "require": { - "php": ">=5.3" + "php": ">=7.1" }, "extra": { "display-name": "phpBB Gallery Add-on: ACP Cleanup", "soft-require": { - "phpbb/phpbb": ">=3.1.0-RC2,<3.3.0@dev" + "phpbb/phpbb": ">=3.2.0,<4.0.0@dev" } }, "version-check": { diff --git a/acpcleanup/config/services.yml b/acpcleanup/config/services.yml index 0ef56a9a1..f2c0d6f82 100644 --- a/acpcleanup/config/services.yml +++ b/acpcleanup/config/services.yml @@ -1,6 +1,6 @@ parameters: - tables.phpbbgallery.albums: '%core.table_prefix%gallery_albums' - tables.phpbbgallery.images: '%core.table_prefix%gallery_images' + phpbbgallery.tables.gallery_albums: '%core.table_prefix%gallery_albums' + phpbbgallery.tables.gallery_images: '%core.table_prefix%gallery_images' services: phpbbgallery.acpcleanup.cleanup: @@ -16,5 +16,5 @@ services: - '@phpbbgallery.core.config' - '@phpbbgallery.core.log' - '@phpbbgallery.core.moderate' - - '%tables.phpbbgallery.albums%' - - '%tables.phpbbgallery.images%' \ No newline at end of file + - '%phpbbgallery.tables.gallery_albums%' + - '%phpbbgallery.tables.gallery_images%' \ No newline at end of file diff --git a/acpcleanup/ext.php b/acpcleanup/ext.php index 7fd37f24e..ade3dfa8f 100644 --- a/acpcleanup/ext.php +++ b/acpcleanup/ext.php @@ -8,12 +8,59 @@ * @license GPL-2.0-only */ -// this file is not really needed, when empty it can be omitted -// however you can override the default methods and add custom -// installation logic - namespace phpbbgallery\acpcleanup; class ext extends \phpbb\extension\base { + /** + * Check whether or not the extension can be enabled. + * Checks dependencies and requirements. + * + * @return bool + */ + public function is_enableable() + { + $manager = $this->container->get('ext.manager'); + $user = $this->container->get('user'); + + $core_ext = 'phpbbgallery/core'; + + // Check if core is installed (enabled or disabled) + $is_enabled = $manager->is_enabled($core_ext); + $is_disabled = $manager->is_disabled($core_ext); + + if (!$is_enabled && !$is_disabled) + { + // Core not installed at all + $user->add_lang_ext('phpbbgallery/acpcleanup', 'info_acp_gallery_cleanup'); + trigger_error($user->lang('GALLERY_CORE_NOT_FOUND'), E_USER_WARNING); + return false; + } + + if ($is_disabled) + { + // Core installed but disabled — enable it automatically + $manager->enable($core_ext); + } + + // If here, core is either enabled or just enabled now + return true; + } + + /** + * Perform additional tasks on extension enable + * + * @param mixed $old_state State returned by previous call of this method + * @return mixed Returns false after last step, otherwise temporary state + */ + public function enable_step($old_state) + { + if (empty($old_state)) + { + $this->container->get('user')->add_lang_ext('phpbbgallery/acpcleanup', 'info_acp_gallery_cleanup'); + $this->container->get('template')->assign_var('L_EXTENSION_ENABLE_SUCCESS', $this->container->get('user')->lang['EXTENSION_ENABLE_SUCCESS']); + } + + return parent::enable_step($old_state); + } } diff --git a/exif/language/en/index copy.htm b/acpcleanup/language/bg/index.htm similarity index 100% rename from exif/language/en/index copy.htm rename to acpcleanup/language/bg/index.htm diff --git a/acpcleanup/language/bg/info_acp_gallery_cleanup.php b/acpcleanup/language/bg/info_acp_gallery_cleanup.php index e69491a6e..2618cc0c3 100644 --- a/acpcleanup/language/bg/info_acp_gallery_cleanup.php +++ b/acpcleanup/language/bg/info_acp_gallery_cleanup.php @@ -21,10 +21,10 @@ if (empty($lang) || !is_array($lang)) { - $lang = array(); + $lang = []; } -$lang = array_merge($lang, array( +$lang = array_merge($lang, [ 'ACP_GALLERY_CLEANUP' => 'Почистване на галерия', 'ACP_GALLERY_CLEANUP_EXPLAIN' => 'Тук можете да изтриете малко останки.', @@ -78,4 +78,7 @@ 'MOVE_TO_USER' => 'Премести при потребител', 'MOVE_TO_USER_EXP' => 'Изображенията и коментарите ще бъдат преместеи като такива на посочения потребител. Ако не посочите потребител - Гост е зададен по-подразбиране', 'CLEAN_USER_NOT_FOUND' => 'Желаният от вас потребител не е открит!', -)); + + 'GALLERY_CORE_NOT_FOUND' => 'Първо трябва да бъде инсталирано и активирано разширението phpBB Gallery Core.', + 'EXTENSION_ENABLE_SUCCESS' => 'Разширението е активирано успешно.', +]); diff --git a/acpcleanup/language/de/index.htm b/acpcleanup/language/de/index.htm new file mode 100644 index 000000000..e69de29bb diff --git a/acpcleanup/language/de/info_acp_gallery_cleanup.php b/acpcleanup/language/de/info_acp_gallery_cleanup.php index 5a9051ecb..09524687d 100644 --- a/acpcleanup/language/de/info_acp_gallery_cleanup.php +++ b/acpcleanup/language/de/info_acp_gallery_cleanup.php @@ -21,10 +21,10 @@ if (empty($lang) || !is_array($lang)) { - $lang = array(); + $lang = []; } -$lang = array_merge($lang, array( +$lang = array_merge($lang, [ 'ACP_GALLERY_CLEANUP' => 'Galerie bereinigen', 'ACP_GALLERY_CLEANUP_EXPLAIN' => 'Hier kannst Du einige Reste löschen.', @@ -79,4 +79,7 @@ 'MOVE_TO_USER' => 'Wechseln zu Benutzer', 'MOVE_TO_USER_EXP' => 'Bilder und Kommentare werden als diejenigen des Benutzers verschoben werden, die Du definiert hast. Wenn Keine ausgewählt wird - wird Gast verwendet.', 'CLEAN_USER_NOT_FOUND' => 'Der von Ihnen ausgewählte Benutzer existiert nicht!', -)); + + 'GALLERY_CORE_NOT_FOUND' => 'Die phpBB Gallery Core-Erweiterung muss zuerst installiert und aktiviert werden.', + 'EXTENSION_ENABLE_SUCCESS' => 'Die Erweiterung wurde erfolgreich aktiviert.', +]); diff --git a/acpcleanup/language/en/index.htm b/acpcleanup/language/en/index.htm new file mode 100644 index 000000000..e69de29bb diff --git a/acpcleanup/language/en/info_acp_gallery_cleanup.php b/acpcleanup/language/en/info_acp_gallery_cleanup.php index 8d585777b..0c0867089 100644 --- a/acpcleanup/language/en/info_acp_gallery_cleanup.php +++ b/acpcleanup/language/en/info_acp_gallery_cleanup.php @@ -20,10 +20,10 @@ if (empty($lang) || !is_array($lang)) { - $lang = array(); + $lang = []; } -$lang = array_merge($lang, array( +$lang = array_merge($lang, [ 'ACP_GALLERY_CLEANUP' => 'Cleanup gallery', 'ACP_GALLERY_CLEANUP_EXPLAIN' => 'Here you can delete some remains.', @@ -78,4 +78,7 @@ 'MOVE_TO_USER' => 'Move to user', 'MOVE_TO_USER_EXP' => 'Images and comments will be moved as those of user you have defined. If none is selected - Anonymous will be used.', 'CLEAN_USER_NOT_FOUND' => 'The user you selected does not exists!', -)); + + 'GALLERY_CORE_NOT_FOUND' => 'phpBB Gallery Core extension must be installed and enabled first.', + 'EXTENSION_ENABLE_SUCCESS' => 'The extension has been enabled successfully.', +]); diff --git a/acpcleanup/language/fr/index.htm b/acpcleanup/language/fr/index.htm new file mode 100644 index 000000000..e69de29bb diff --git a/acpcleanup/language/fr/info_acp_gallery_cleanup.php b/acpcleanup/language/fr/info_acp_gallery_cleanup.php index 18700e6d7..4573f30b5 100644 --- a/acpcleanup/language/fr/info_acp_gallery_cleanup.php +++ b/acpcleanup/language/fr/info_acp_gallery_cleanup.php @@ -21,10 +21,10 @@ if (empty($lang) || !is_array($lang)) { - $lang = array(); + $lang = []; } -$lang = array_merge($lang, array( +$lang = array_merge($lang, [ 'ACP_GALLERY_CLEANUP' => 'Nettoyage de la galerie', 'ACP_GALLERY_CLEANUP_EXPLAIN' => 'Ici vous pouvez nettoyer la Galerie.', @@ -79,4 +79,7 @@ 'MOVE_TO_USER' => 'Attribuer à l’utilisateur', 'MOVE_TO_USER_EXP' => 'Les images et les commentaires seront attribués à l’utilisateur que vous avez défini. Si aucun n’est sélectionné - “Anonyme“ sera utilisé.', 'CLEAN_USER_NOT_FOUND' => 'L’utilisateur sélectionné n’existe pas!', -)); + + 'GALLERY_CORE_NOT_FOUND' => 'L’extension phpBB Gallery Core doit d’abord être installée et activée.', + 'EXTENSION_ENABLE_SUCCESS' => 'L’extension a été activée avec succès.', +]); diff --git a/acpcleanup/language/it/index.htm b/acpcleanup/language/it/index.htm new file mode 100644 index 000000000..e69de29bb diff --git a/acpcleanup/language/it/info_acp_gallery_cleanup.php b/acpcleanup/language/it/info_acp_gallery_cleanup.php index 67404cb8b..a392dad2f 100644 --- a/acpcleanup/language/it/info_acp_gallery_cleanup.php +++ b/acpcleanup/language/it/info_acp_gallery_cleanup.php @@ -21,10 +21,10 @@ if (empty($lang) || !is_array($lang)) { - $lang = array(); + $lang = []; } -$lang = array_merge($lang, array( +$lang = array_merge($lang, [ 'ACP_GALLERY_CLEANUP' => 'Pulisci galleria', 'ACP_GALLERY_CLEANUP_EXPLAIN' => 'Puoi cancellare alcuni rimasugli, da qui.', @@ -79,4 +79,7 @@ 'MOVE_TO_USER' => 'Sposta all\'utente', 'MOVE_TO_USER_EXP' => 'Immagini e commenti verranno spostati come fossero dell\'utente che hai definito. Se non ne vengono selezionati verra\' usato l\'utente anonimo.', 'CLEAN_USER_NOT_FOUND' => 'L\'utente selezionato non esiste!', -)); + + 'GALLERY_CORE_NOT_FOUND' => 'L\'estensione phpBB Gallery Core deve essere prima installata e abilitata.', + 'EXTENSION_ENABLE_SUCCESS' => 'L\'estensione è stata abilitata con successo.', +]); diff --git a/acpcleanup/language/ru/index.htm b/acpcleanup/language/ru/index.htm new file mode 100644 index 000000000..e69de29bb diff --git a/acpcleanup/language/ru/info_acp_gallery_cleanup.php b/acpcleanup/language/ru/info_acp_gallery_cleanup.php index 451ba9f28..4c5800b43 100644 --- a/acpcleanup/language/ru/info_acp_gallery_cleanup.php +++ b/acpcleanup/language/ru/info_acp_gallery_cleanup.php @@ -21,10 +21,10 @@ if (empty($lang) || !is_array($lang)) { - $lang = array(); + $lang = []; } -$lang = array_merge($lang, array( +$lang = array_merge($lang, [ 'ACP_GALLERY_CLEANUP' => 'Очистить галерею', 'ACP_GALLERY_CLEANUP_EXPLAIN' => 'Здесь вы можете удалить некоторые остатки.', @@ -79,4 +79,7 @@ 'MOVE_TO_USER' => 'Move to user', 'MOVE_TO_USER_EXP' => 'Images and comments will be moved as those of user you have defined. If none is selected - Anonymous will be used.', 'CLEAN_USER_NOT_FOUND' => 'The user you selected does not exists!', - )); + + 'GALLERY_CORE_NOT_FOUND' => 'Сначала необходимо установить и включить расширение phpBB Gallery Core.', + 'EXTENSION_ENABLE_SUCCESS' => 'Расширение успешно включено.', +]); diff --git a/acpcleanup/migrations/m1_init.php b/acpcleanup/migrations/m1_init.php index 5a3dfeb9b..17b741e76 100644 --- a/acpcleanup/migrations/m1_init.php +++ b/acpcleanup/migrations/m1_init.php @@ -12,27 +12,29 @@ namespace phpbbgallery\acpcleanup\migrations; -class m1_init extends \phpbb\db\migration\migration +use phpbb\db\migration\migration; + +class m1_init extends migration { static public function depends_on() { - return array('\phpbbgallery\core\migrations\release_1_2_0'); + return ['\phpbbgallery\core\migrations\release_1_2_0']; } public function update_data() { - return array( - array('permission.add', array('a_gallery_cleanup', true, 'a_board')), - array('module.add', array( - 'acp', - 'PHPBB_GALLERY', - array( - 'module_basename' => '\phpbbgallery\acpcleanup\acp\main_module', - 'module_langname' => 'ACP_GALLERY_CLEANUP', - 'module_mode' => 'cleanup', - 'module_auth' => 'ext_phpbbgallery/acpcleanup && acl_a_gallery_cleanup', - ) - )), - ); + return [ + ['permission.add', ['a_gallery_cleanup', true, 'a_board']], + ['module.add', [ + 'acp', + 'PHPBB_GALLERY', + [ + 'module_basename' => '\phpbbgallery\acpcleanup\acp\main_module', + 'module_langname' => 'ACP_GALLERY_CLEANUP', + 'module_mode' => 'cleanup', + 'module_auth' => 'ext_phpbbgallery/acpcleanup && acl_a_gallery_cleanup', + ] + ]], + ]; } } diff --git a/acpimport/acp/main_info.php b/acpimport/acp/main_info.php index 96fac1344..28899f156 100644 --- a/acpimport/acp/main_info.php +++ b/acpimport/acp/main_info.php @@ -12,21 +12,29 @@ namespace phpbbgallery\acpimport\acp; +/** + * ACP Module Info class for Gallery Import + */ class main_info { - function module() + /** + * Returns module information + * + * @return array Module configuration + */ + public function module(): array { - return array( - 'filename' => 'main_module', - 'title' => 'PHPBB_GALLERY', - 'version' => '1.0.0', - 'modes' => array( - 'import_images' => array( - 'title' => 'ACP_IMPORT_ALBUMS', - 'auth' => 'acl_a_gallery_import && ext_phpbbgallery/acpimport', - 'cat' => array('PHPBB_GALLERY') - ), - ), - ); + return [ + 'filename' => '\phpbbgallery\acpimport\acp\main_module', + 'title' => 'PHPBB_GALLERY', + 'version' => '1.0.0', + 'modes' => [ + 'import_images' => [ + 'title' => 'ACP_IMPORT_ALBUMS', + 'auth' => 'ext_phpbbgallery/acpimport && acl_a_gallery_import', + 'cat' => ['PHPBB_GALLERY'], + ], + ], + ]; } } diff --git a/acpimport/adm/style/gallery_acpimport.html b/acpimport/adm/style/gallery_acpimport.html index 8577b566c..f64596297 100644 --- a/acpimport/adm/style/gallery_acpimport.html +++ b/acpimport/adm/style/gallery_acpimport.html @@ -47,15 +47,4 @@