Skip to content

Commit 9221622

Browse files
authored
Merge pull request #340 from Leinad4Mind/master
Refactor Enabling/Disabling/Purging Logic + Update Code
2 parents f9e04fa + fc4a868 commit 9221622

File tree

160 files changed

+969
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+969
-560
lines changed

acpcleanup/acp/main_info.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,29 @@
1212

1313
namespace phpbbgallery\acpcleanup\acp;
1414

15+
/**
16+
* ACP Module Info class
17+
*/
1518
class main_info
1619
{
17-
function module()
20+
/**
21+
* Returns module information
22+
*
23+
* @return array Module information
24+
*/
25+
public function module(): array
1826
{
19-
return array(
20-
'filename' => 'main_module',
21-
'title' => 'PHPBB_GALLERY',
22-
'version' => '1.0.0',
23-
'modes' => array(
24-
'cleanup' => array(
25-
'title' => 'ACP_GALLERY_CLEANUP',
26-
'auth' => 'acl_a_gallery_cleanup && ext_phpbbgallery/acpcleanup',
27-
'cat' => array('PHPBB_GALLERY')
28-
),
29-
),
30-
);
27+
return [
28+
'filename' => '\phpbbgallery\acpcleanup\acp\main_module',
29+
'title' => 'PHPBB_GALLERY',
30+
'version' => '1.0.0',
31+
'modes' => [
32+
'cleanup' => [
33+
'title' => 'ACP_GALLERY_CLEANUP',
34+
'auth' => 'acl_a_gallery_cleanup && ext_phpbbgallery/acpcleanup',
35+
'cat' => ['PHPBB_GALLERY'],
36+
],
37+
],
38+
];
3139
}
3240
}

acpcleanup/acp/main_module.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,42 @@
1414

1515
class main_module
1616
{
17-
var $u_action;
17+
public string $u_action;
1818

19-
function main($id, $mode)
19+
public function main(string $id, string $mode): void
2020
{
21-
global $auth, $cache, $config, $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_ext_gallery;
21+
global $auth, $cache, $config, $db, $template, $request, $user, $phpEx, $phpbb_root_path, $phpbb_ext_gallery;
2222

2323
$user->add_lang_ext('phpbbgallery/core', array('gallery_acp', 'gallery'));
24-
//$user->add_lang_ext('phpbbgallery/acpcleanup', 'cleanup');
2524
$this->tpl_name = 'gallery_cleanup';
25+
2626
add_form_key('acp_gallery');
2727

28+
$submit = $request->is_set_post('submit');
29+
30+
if ($submit && !check_form_key('acp_gallery'))
31+
{
32+
trigger_error($user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING);
33+
}
34+
2835
$this->page_title = $user->lang['ACP_GALLERY_CLEANUP'];
29-
$this->cleanup();
36+
$this->cleanup($submit);
3037
}
3138

32-
function cleanup()
39+
/**
40+
* Cleanup gallery files and database entries
41+
*
42+
* @param array $missing_entries Files to clean
43+
* @param bool $move_to_import Whether to move files to import dir
44+
* @return array Messages about cleanup results
45+
* @throws \RuntimeException On file operation errors
46+
*/
47+
public function cleanup(bool $submit = false): void
3348
{
3449
global $auth, $cache, $db, $template, $user, $phpbb_ext_gallery, $table_prefix, $phpbb_container, $request;
3550

36-
$delete = (isset($_POST['delete'])) ? true : false;
37-
$prune = (isset($_POST['prune'])) ? true : false;
38-
$submit = (isset($_POST['submit'])) ? true : false;
51+
$delete = $request->is_set_post('delete');
52+
$prune = $request->is_set_post('prune');
3953

4054
$missing_sources = $request->variable('source', array(0));
4155
$missing_entries = $request->variable('entry', array(''), true);

acpcleanup/adm/style/gallery_cleanup.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,10 @@ <h1>{ACP_GALLERY_TITLE}</h1>
147147

148148
<p class="submit-buttons">
149149
<input class="button1" type="submit" name="prune" value="{L_PRUNE}" />
150+
{S_FORM_TOKEN}
150151
</p>
151152
</fieldset>
152153
<!-- ENDIF -->
153-
<p>{S_FORM_TOKEN}</p>
154154
</form>
155155

156-
<!--
157-
I request you retain the full copyright notice below including the link to www.flying-bits.org.
158-
This not only gives respect to the large amount of time given freely by the developer
159-
but also helps build interest, traffic and use of phpBB Gallery. If you (honestly) cannot retain
160-
the full copyright I ask you at least leave in place the "Powered by phpBB Gallery" line, with
161-
"phpBB Gallery" linked to www.flying-bits.org. If you refuse to include even this then support on my
162-
forums may be affected.
163-
164-
phpBB Gallery, nickvergessen : 2009
165-
Powered by phpBB Gallery (http://www.flying-bits.org/) &copy; 2007, 2009 nickvergessen (http://www.flying-bits.org/)
166-
//-->
167156
<!-- INCLUDE overall_footer.html -->

acpcleanup/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
}
2727
],
2828
"require": {
29-
"php": ">=5.3"
29+
"php": ">=7.1"
3030
},
3131
"extra": {
3232
"display-name": "phpBB Gallery Add-on: ACP Cleanup",
3333
"soft-require": {
34-
"phpbb/phpbb": ">=3.1.0-RC2,<3.3.0@dev"
34+
"phpbb/phpbb": ">=3.2.0,<4.0.0@dev"
3535
}
3636
},
3737
"version-check": {

acpcleanup/config/services.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parameters:
2-
tables.phpbbgallery.albums: '%core.table_prefix%gallery_albums'
3-
tables.phpbbgallery.images: '%core.table_prefix%gallery_images'
2+
phpbbgallery.tables.gallery_albums: '%core.table_prefix%gallery_albums'
3+
phpbbgallery.tables.gallery_images: '%core.table_prefix%gallery_images'
44

55
services:
66
phpbbgallery.acpcleanup.cleanup:
@@ -16,5 +16,5 @@ services:
1616
- '@phpbbgallery.core.config'
1717
- '@phpbbgallery.core.log'
1818
- '@phpbbgallery.core.moderate'
19-
- '%tables.phpbbgallery.albums%'
20-
- '%tables.phpbbgallery.images%'
19+
- '%phpbbgallery.tables.gallery_albums%'
20+
- '%phpbbgallery.tables.gallery_images%'

acpcleanup/ext.php

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,59 @@
88
* @license GPL-2.0-only
99
*/
1010

11-
// this file is not really needed, when empty it can be omitted
12-
// however you can override the default methods and add custom
13-
// installation logic
14-
1511
namespace phpbbgallery\acpcleanup;
1612

1713
class ext extends \phpbb\extension\base
1814
{
15+
/**
16+
* Check whether or not the extension can be enabled.
17+
* Checks dependencies and requirements.
18+
*
19+
* @return bool
20+
*/
21+
public function is_enableable()
22+
{
23+
$manager = $this->container->get('ext.manager');
24+
$user = $this->container->get('user');
25+
26+
$core_ext = 'phpbbgallery/core';
27+
28+
// Check if core is installed (enabled or disabled)
29+
$is_enabled = $manager->is_enabled($core_ext);
30+
$is_disabled = $manager->is_disabled($core_ext);
31+
32+
if (!$is_enabled && !$is_disabled)
33+
{
34+
// Core not installed at all
35+
$user->add_lang_ext('phpbbgallery/acpcleanup', 'info_acp_gallery_cleanup');
36+
trigger_error($user->lang('GALLERY_CORE_NOT_FOUND'), E_USER_WARNING);
37+
return false;
38+
}
39+
40+
if ($is_disabled)
41+
{
42+
// Core installed but disabled — enable it automatically
43+
$manager->enable($core_ext);
44+
}
45+
46+
// If here, core is either enabled or just enabled now
47+
return true;
48+
}
49+
50+
/**
51+
* Perform additional tasks on extension enable
52+
*
53+
* @param mixed $old_state State returned by previous call of this method
54+
* @return mixed Returns false after last step, otherwise temporary state
55+
*/
56+
public function enable_step($old_state)
57+
{
58+
if (empty($old_state))
59+
{
60+
$this->container->get('user')->add_lang_ext('phpbbgallery/acpcleanup', 'info_acp_gallery_cleanup');
61+
$this->container->get('template')->assign_var('L_EXTENSION_ENABLE_SUCCESS', $this->container->get('user')->lang['EXTENSION_ENABLE_SUCCESS']);
62+
}
63+
64+
return parent::enable_step($old_state);
65+
}
1966
}

acpcleanup/language/bg/info_acp_gallery_cleanup.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
if (empty($lang) || !is_array($lang))
2323
{
24-
$lang = array();
24+
$lang = [];
2525
}
2626

27-
$lang = array_merge($lang, array(
27+
$lang = array_merge($lang, [
2828
'ACP_GALLERY_CLEANUP' => 'Почистване на галерия',
2929
'ACP_GALLERY_CLEANUP_EXPLAIN' => 'Тук можете да изтриете малко останки.',
3030

@@ -78,4 +78,7 @@
7878
'MOVE_TO_USER' => 'Премести при потребител',
7979
'MOVE_TO_USER_EXP' => 'Изображенията и коментарите ще бъдат преместеи като такива на посочения потребител. Ако не посочите потребител - Гост е зададен по-подразбиране',
8080
'CLEAN_USER_NOT_FOUND' => 'Желаният от вас потребител не е открит!',
81-
));
81+
82+
'GALLERY_CORE_NOT_FOUND' => 'Първо трябва да бъде инсталирано и активирано разширението phpBB Gallery Core.',
83+
'EXTENSION_ENABLE_SUCCESS' => 'Разширението е активирано успешно.',
84+
]);

acpcleanup/language/de/index.htm

Whitespace-only changes.

acpcleanup/language/de/info_acp_gallery_cleanup.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
if (empty($lang) || !is_array($lang))
2323
{
24-
$lang = array();
24+
$lang = [];
2525
}
2626

27-
$lang = array_merge($lang, array(
27+
$lang = array_merge($lang, [
2828
'ACP_GALLERY_CLEANUP' => 'Galerie bereinigen',
2929

3030
'ACP_GALLERY_CLEANUP_EXPLAIN' => 'Hier kannst Du einige Reste löschen.',
@@ -79,4 +79,7 @@
7979
'MOVE_TO_USER' => 'Wechseln zu Benutzer',
8080
'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.',
8181
'CLEAN_USER_NOT_FOUND' => 'Der von Ihnen ausgewählte Benutzer existiert nicht!',
82-
));
82+
83+
'GALLERY_CORE_NOT_FOUND' => 'Die phpBB Gallery Core-Erweiterung muss zuerst installiert und aktiviert werden.',
84+
'EXTENSION_ENABLE_SUCCESS' => 'Die Erweiterung wurde erfolgreich aktiviert.',
85+
]);

0 commit comments

Comments
 (0)