Skip to content

Commit f5840f5

Browse files
committed
Rever path helper stuff
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent b021d6c commit f5840f5

5 files changed

Lines changed: 6 additions & 57 deletions

File tree

config/services.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ services:
2828
- '@log'
2929
- '@user_loader'
3030
- '@user'
31-
- '@path_helper'
3231
- '%core.root_path%'
3332
- '%core.php_ext%'
3433
- '%tables.phpbb.wpn.notification_push%'

notification/method/webpush.php

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use phpbb\log\log_interface;
1818
use phpbb\notification\method\messenger_base;
1919
use phpbb\notification\type\type_interface;
20-
use phpbb\path_helper;
2120
use phpbb\user;
2221
use phpbb\user_loader;
2322
use phpbb\webpushnotifications\form\form_helper;
@@ -42,9 +41,6 @@ class webpush extends messenger_base implements extended_method_interface
4241
/** @var user */
4342
protected $user;
4443

45-
/** @var path_helper */
46-
protected $path_helper;
47-
4844
/** @var string Notification Web Push table */
4945
protected $notification_webpush_table;
5046

@@ -59,22 +55,20 @@ class webpush extends messenger_base implements extended_method_interface
5955
* @param log_interface $log
6056
* @param user_loader $user_loader
6157
* @param user $user
62-
* @param path_helper $path_helper
6358
* @param string $phpbb_root_path
6459
* @param string $php_ext
6560
* @param string $notification_webpush_table
6661
* @param string $push_subscriptions_table
6762
*/
68-
public function __construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user, path_helper $path_helper,
69-
string $phpbb_root_path, string $php_ext, string $notification_webpush_table, string $push_subscriptions_table)
63+
public function __construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user, string $phpbb_root_path,
64+
string $php_ext, string $notification_webpush_table, string $push_subscriptions_table)
7065
{
7166
parent::__construct($user_loader, $phpbb_root_path, $php_ext);
7267

7368
$this->config = $config;
7469
$this->db = $db;
7570
$this->log = $log;
7671
$this->user = $user;
77-
$this->path_helper = $path_helper;
7872
$this->notification_webpush_table = $notification_webpush_table;
7973
$this->push_subscriptions_table = $push_subscriptions_table;
8074
}
@@ -436,16 +430,10 @@ protected function clean_expired_subscriptions(array $user_subscription_map, arr
436430
}
437431

438432
/**
439-
* Takes an avatar string (usually in full html format already) and extracts the url.
440-
* If the avatar url is a relative path, it's converted to an absolute path.
441-
*
442-
* Converts:
443-
* <img class="avatar" src="./path/to/avatar=123456789.gif" width="123" height="123" alt="User avatar" />
444-
* or <img class="avatar" src="./styles/prosilver/theme/images/no_avatar.gif" data-src="./path/to/avatar=123456789.gif" width="123" height="123" alt="User avatar" />
445-
* into https://myboard.url/path/to/avatar=123456789.gif
433+
* Takes an avatar string (usually in full html format already) and extracts the src path.
446434
*
447435
* @param string $avatar
448-
* @return string Absolute path to avatar image
436+
* @return array
449437
*/
450438
protected function prepare_avatar($avatar)
451439
{
@@ -455,23 +443,6 @@ protected function prepare_avatar($avatar)
455443

456444
$path = !empty($matches[1]) ? end($matches[1]) : $avatar;
457445

458-
return preg_replace('#^' . preg_quote($this->path_helper->get_web_root_path(), '#') . '#', $this->get_board_url(), $path, 1);
459-
}
460-
461-
/**
462-
* Returns the board url (and caches it in the function)
463-
*
464-
* @return string the generated board url
465-
*/
466-
protected function get_board_url()
467-
{
468-
static $board_url;
469-
470-
if (empty($board_url))
471-
{
472-
$board_url = generate_board_url() . '/';
473-
}
474-
475-
return $board_url;
446+
return ['src' => preg_replace('#^\./#', '/', $path)];
476447
}
477448
}

styles/all/template/push_worker.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ self.addEventListener('push', event => {
3636
const options = {
3737
body: responseBody,
3838
data: response,
39-
icon: response.avatar,
39+
icon: response.avatar.src,
4040
};
4141
self.registration.showNotification(response.heading, options);
4242
});

tests/event/listener_test.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,12 @@ protected function setUp(): void
7676
$this->user
7777
);
7878

79-
$path_helper = $this->getMockBuilder('\phpbb\path_helper')
80-
->disableOriginalConstructor()
81-
->setMethods(array())
82-
->getMock();
83-
8479
$this->notification_method_webpush = new \phpbb\webpushnotifications\notification\method\webpush(
8580
$this->config,
8681
$db,
8782
new \phpbb\log\dummy(),
8883
$user_loader,
8984
$this->user,
90-
$path_helper,
9185
$phpbb_root_path,
9286
$phpEx,
9387
'phpbb_wpn_notification_push',

tests/notification/notification_method_webpush_test.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,6 @@ protected function setUp(): void
128128
$phpEx
129129
);
130130

131-
$request = new \phpbb_mock_request;
132-
$symfony_request = new \phpbb\symfony_request(
133-
$request
134-
);
135-
$filesystem = new \phpbb\filesystem\filesystem();
136-
$phpbb_path_helper = new \phpbb\path_helper(
137-
$symfony_request,
138-
$filesystem,
139-
$request,
140-
$phpbb_root_path,
141-
$phpEx
142-
);
143-
144131
$log_table = 'phpbb_log';
145132
$this->log = new \phpbb\log\log($this->db, $user, $auth, $this->phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, $log_table);
146133

@@ -158,7 +145,6 @@ protected function setUp(): void
158145
$phpbb_container->set('log', $this->log);
159146
$phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils());
160147
$phpbb_container->set('dispatcher', $this->phpbb_dispatcher);
161-
$phpbb_container->set('path_helper', $phpbb_path_helper);
162148
$phpbb_container->setParameter('core.root_path', $phpbb_root_path);
163149
$phpbb_container->setParameter('core.php_ext', $phpEx);
164150
$phpbb_container->setParameter('tables.notifications', 'phpbb_notifications');
@@ -174,7 +160,6 @@ protected function setUp(): void
174160
$phpbb_container->get('log'),
175161
$phpbb_container->get('user_loader'),
176162
$phpbb_container->get('user'),
177-
$phpbb_container->get('path_helper'),
178163
$phpbb_root_path,
179164
$phpEx,
180165
$phpbb_container->getParameter('tables.phpbb.wpn.notification_push'),

0 commit comments

Comments
 (0)