Skip to content

Commit 23dd8f1

Browse files
committed
Use router to generate url, add language keys and improve migration
1 parent f3889bc commit 23dd8f1

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ services:
5454
phpbb.ads.admin.input:
5555
class: phpbb\ads\controller\admin_input
5656
arguments:
57+
- '@controller.helper'
5758
- '@user'
5859
- '@user_loader'
5960
- '@language'

controller/admin_input.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*/
1818
class admin_input
1919
{
20+
/** @var \phpbb\controller\helper */
21+
protected $controller_helper;
22+
2023
/** @var \phpbb\user */
2124
protected $user;
2225

@@ -44,8 +47,9 @@ class admin_input
4447
* @param \phpbb\request\request $request Request object
4548
* @param \phpbb\ads\banner\banner $banner Banner upload object
4649
*/
47-
public function __construct(\phpbb\user $user, \phpbb\user_loader $user_loader, \phpbb\language\language $language, \phpbb\request\request $request, \phpbb\ads\banner\banner $banner)
50+
public function __construct(\phpbb\controller\helper $controller_helper, \phpbb\user $user, \phpbb\user_loader $user_loader, \phpbb\language\language $language, \phpbb\request\request $request, \phpbb\ads\banner\banner $banner)
4851
{
52+
$this->controller_helper = $controller_helper;
4953
$this->user = $user;
5054
$this->user_loader = $user_loader;
5155
$this->language = $language;
@@ -136,7 +140,7 @@ public function banner_upload($ad_code)
136140
{
137141
$realname = $this->banner->upload();
138142

139-
$banner_html = '<img src="' . generate_board_url() . '/ads_download/' . $realname . '" />';
143+
$banner_html = '<img src="' . generate_board_url() . $this->controller_helper->route('phpbb_ads_storage_banner', ['file' => $realname]) . '" />';
140144

141145
if ($this->request->is_ajax())
142146
{

language/en/common.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@
6666
'AD_SLIDE_UP_DESC' => 'Displays on every page after user scrolls below main content. Slides up from the bottom.',
6767
'AD_SCRIPTS' => 'Scripts',
6868
'AD_SCRIPTS_DESC' => 'This location is for specialty JavaScript code like AdSense Auto ads, tracking codes, etc. The code entered here will be inserted into the page’s HEAD tag and is not intended for ad placement, but only for helper scripts.',
69+
70+
// Storage
71+
'STORAGE_PHPBB_ADS_TITLE' => 'phpBB Ads',
6972
));

migrations/v30x/m1_storage.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@
1010

1111
namespace phpbb\ads\migrations\v30x;
1212

13+
use phpbb\filesystem\filesystem;
1314
use phpbb\storage\provider\local;
1415

1516
class m1_storage extends \phpbb\db\migration\container_aware_migration
1617
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function effectively_installed()
22+
{
23+
/** @var filesystem $filesystem_interface */
24+
$filesystem = $this->container->get('filesystem');
25+
26+
return $this->config->offsetExists('storage\\phpbb_ads\\provider') &&
27+
$this->config->offsetExists('storage\\phpbb_ads\\config\\path') &&
28+
$filesystem->exists($this->phpbb_root_path . 'images/phpbb_ads');
29+
}
30+
1731
/**
1832
* {@inheritDoc}
1933
*/
@@ -29,15 +43,54 @@ public function update_data()
2943
{
3044
return array(
3145
['config.add', ['storage\\phpbb_ads\\provider', local::class]],
32-
['config.add', ['storage\\phpbb_ads\\config\\path', 'images/phpbb_ads']], // todo: make sure this exists in migration if is a new installation
46+
['config.add', ['storage\\phpbb_ads\\config\\path', 'images/phpbb_ads']],
47+
['custom', [[$this, 'migrate_ads_storage']]],
3348
);
3449
}
3550

51+
public function migrate_ads_storage()
52+
{
53+
/** @var filesystem $filesystem_interface */
54+
$filesystem = $this->container->get('filesystem');
55+
56+
/** @var file_tracker $file_tracker */
57+
$file_tracker = $this->container->get('storage.file_tracker');
58+
59+
if (!$filesystem->exists($this->phpbb_root_path . 'images/phpbb_ads'))
60+
{
61+
$filesystem->mkdir($this->phpbb_root_path . 'images/phpbb_ads');
62+
}
63+
64+
$dir = $this->phpbb_root_path . 'images/phpbb_ads';
65+
$handle = @opendir($dir);
66+
67+
if ($handle)
68+
{
69+
while (($file = readdir($handle)) !== false)
70+
{
71+
if ($file === '.' || $file === '..')
72+
{
73+
continue;
74+
}
75+
76+
$file_tracker->track_file('phpbb_ads', $file, filesize($this->phpbb_root_path . 'images/phpbb_ads/' . $file));
77+
}
78+
79+
closedir($handle);
80+
}
81+
}
82+
3683
public function revert_data()
3784
{
3885
return [
3986
['config.remove', ['storage\\phpbb_ads\\provider']],
4087
['config.remove', ['storage\\phpbb_ads\\config\\path']],
88+
['custom', [[$this, 'revert_ads_storage']]],
4189
];
4290
}
91+
92+
public function revert_ads_storage()
93+
{
94+
$this->sql_query('DELETE FROM ' . $this->tables['storage'] . ' WHERE storage = "phpbb_ads"');
95+
}
4396
}

0 commit comments

Comments
 (0)