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');
24 function fancybox_footer(App $a, string &$str)
26 DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/jquery.fancybox.min.js');
27 DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/fancybox.config.js');
34 Called at the end of prepare_body(). Hook data:
36 item: item array (input)
37 html: converted item body (input/output)
41 function fancybox_render(App $a, array &$b) {
43 $pattern='#<div class="body-attach">.*?</div>#s';
45 if (array_key_exists('item', $b)) {
47 if (array_key_exists('uri-id', $item)) {
48 $gallery = $gallery . '-' . $item['uri-id'];
52 while (preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)) {
53 if (is_array($matches)) $matches=$matches[0];
55 $replaced = str_replace('<a href', '<a data-fancybox="' . $gallery . '" href', $part);
56 $replaced = str_replace('<div class="body-attach"', '<div class="body-attach done"', $replaced);
57 $html =str_replace($part, $replaced, $html);
59 $html = str_replace('class="body-attach done"', 'class="body-attach"', $html);