@@ -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