4 * Description: Open media attachments of posts into a fancybox overlay.
6 * Author: Grischa Brockhaus <grischa@brockha.us>
10 use Friendica\Core\Hook;
13 function fancybox_install()
15 Hook::register('head', __FILE__, 'fancybox_head');
16 Hook::register('footer', __FILE__, 'fancybox_footer');
17 Hook::register('prepare_body_final', __FILE__, 'fancybox_render');
20 function fancybox_head(App $a, string &$b)
22 DI::page()->registerStylesheet(__DIR__ . '/asset/fancybox/jquery.fancybox.min.css');
25 function fancybox_footer(App $a, string &$str)
27 DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/jquery.fancybox.min.js');
28 DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/fancybox.config.js');
31 function fancybox_render(App $a, array &$b)
34 $pattern = '#<div class="body-attach">.*?</div>#s';
36 if (array_key_exists('item', $b)) {
38 if (array_key_exists('uri-id', $item)) {
39 $gallery = $gallery . '-' . $item['uri-id'];
43 while (preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)) {
44 if (is_array($matches)) {
45 $matches = $matches[0];
48 $replaced = str_replace('<a href', '<a data-fancybox="' . $gallery . '" href', $part);
49 $replaced = str_replace('<div class="body-attach"', '<div class="body-attach done"', $replaced);
50 $html = str_replace($part, $replaced, $html);
52 $html = str_replace('class="body-attach done"', 'class="body-attach"', $html);