Skip to content

Commit 127009f

Browse files
committed
Fix avatar urls after refactorings
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 9ef8134 commit 127009f

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

notification/method/webpush.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -460,46 +460,6 @@ protected function clean_expired_subscriptions(array $user_subscription_map, arr
460460
$this->remove_subscriptions($remove_subscriptions);
461461
}
462462

463-
/**
464-
* Takes an avatar string (usually in full html format already) and extracts the url.
465-
* If the avatar url is a relative path, it's converted to an absolute path.
466-
*
467-
* Converts:
468-
* <img class="avatar" src="./path/to/avatar=123456789.gif" width="123" height="123" alt="User avatar" />
469-
* 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" />
470-
* into https://myboard.url/path/to/avatar=123456789.gif
471-
*
472-
* @param string $avatar
473-
* @return array 'src' => Absolute path to avatar image
474-
*/
475-
protected function prepare_avatar($avatar): array
476-
{
477-
$pattern = '/src=["\']?([^"\'>]+)["\']?/';
478-
479-
preg_match_all($pattern, $avatar, $matches);
480-
481-
$path = !empty($matches[1]) ? end($matches[1]) : $avatar;
482-
483-
return ['src' => preg_replace('#^' . preg_quote($this->path_helper->get_web_root_path(), '#') . '#', $this->get_board_url(), $path, 1)];
484-
}
485-
486-
/**
487-
* Returns the board url (and caches it in the function)
488-
*
489-
* @return string the generated board url
490-
*/
491-
protected function get_board_url()
492-
{
493-
static $board_url;
494-
495-
if (empty($board_url))
496-
{
497-
$board_url = generate_board_url() . '/';
498-
}
499-
500-
return $board_url;
501-
}
502-
503463
/**
504464
* Set web push padding for endpoint
505465
*

ucp/controller/webpush.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private function get_notification_data(string $notification_data): string
243243
'title' => strip_tags(html_entity_decode($notification->get_title(), ENT_NOQUOTES, 'UTF-8')),
244244
'text' => strip_tags(html_entity_decode($notification->get_reference(), ENT_NOQUOTES, 'UTF-8')),
245245
'url' => htmlspecialchars_decode($notification->get_url()),
246-
'avatar' => $notification->get_avatar(),
246+
'avatar' => $this->prepare_avatar($notification->get_avatar()),
247247
]);
248248
}
249249

@@ -346,4 +346,44 @@ public function unsubscribe(symfony_request $symfony_request): JsonResponse
346346
'form_tokens' => $this->form_helper->get_form_tokens(self::FORM_TOKEN_UCP),
347347
]);
348348
}
349+
350+
/**
351+
* Takes an avatar string (usually in full html format already) and extracts the url.
352+
* If the avatar url is a relative path, it's converted to an absolute path.
353+
*
354+
* Converts:
355+
* <img class="avatar" src="./path/to/avatar=123456789.gif" width="123" height="123" alt="User avatar" />
356+
* 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" />
357+
* into https://myboard.url/path/to/avatar=123456789.gif
358+
*
359+
* @param string $avatar
360+
* @return array 'src' => Absolute path to avatar image
361+
*/
362+
protected function prepare_avatar($avatar): array
363+
{
364+
$pattern = '/src=["\']?([^"\'>]+)["\']?/';
365+
366+
preg_match_all($pattern, $avatar, $matches);
367+
368+
$path = !empty($matches[1]) ? end($matches[1]) : $avatar;
369+
370+
return ['src' => preg_replace('#^' . preg_quote($this->path_helper->get_web_root_path(), '#') . '#', $this->get_board_url(), $path, 1)];
371+
}
372+
373+
/**
374+
* Returns the board url (and caches it in the function)
375+
*
376+
* @return string the generated board url
377+
*/
378+
protected function get_board_url()
379+
{
380+
static $board_url;
381+
382+
if (empty($board_url))
383+
{
384+
$board_url = generate_board_url() . '/';
385+
}
386+
387+
return $board_url;
388+
}
349389
}

0 commit comments

Comments
 (0)