Code style

This commit is contained in:
Grischa Brockhaus 2022-11-25 02:05:38 +01:00
parent 1a5b19ff69
commit 537ee2e656

View file

@ -12,50 +12,41 @@ use Friendica\DI;
function fancybox_install() function fancybox_install()
{ {
Hook::register('head', __FILE__, 'fancybox_head'); Hook::register('head', __FILE__, 'fancybox_head');
Hook::register('footer', __FILE__, 'fancybox_footer'); Hook::register('footer', __FILE__, 'fancybox_footer');
Hook::register('prepare_body_final', __FILE__, 'fancybox_render'); Hook::register('prepare_body_final', __FILE__, 'fancybox_render');
} }
function fancybox_head(App $a, string &$b) function fancybox_head(App $a, string &$b)
{ {
DI::page()->registerStylesheet(__DIR__ . '/asset/fancybox/jquery.fancybox.min.css'); DI::page()->registerStylesheet(__DIR__ . '/asset/fancybox/jquery.fancybox.min.css');
} }
function fancybox_footer(App $a, string &$str) function fancybox_footer(App $a, string &$str)
{ {
DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/jquery.fancybox.min.js'); DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/jquery.fancybox.min.js');
DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/fancybox.config.js'); DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/fancybox.config.js');
} }
/* function fancybox_render(App $a, array &$b)
{
prepare_body_final $matches = [];
$pattern = '#<div class="body-attach">.*?</div>#s';
Called at the end of prepare_body(). Hook data: $gallery = 'gallery';
if (array_key_exists('item', $b)) {
item: item array (input) $item = $b['item'];
html: converted item body (input/output) if (array_key_exists('uri-id', $item)) {
$gallery = $gallery . '-' . $item['uri-id'];
*/ }
}
function fancybox_render(App $a, array &$b) { $html = $b['html'];
$matches = []; while (preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)) {
$pattern='#<div class="body-attach">.*?</div>#s'; if (is_array($matches)) $matches = $matches[0];
$gallery = 'gallery'; $part = $matches[0];
if (array_key_exists('item', $b)) { $replaced = str_replace('<a href', '<a data-fancybox="' . $gallery . '" href', $part);
$item = $b['item']; $replaced = str_replace('<div class="body-attach"', '<div class="body-attach done"', $replaced);
if (array_key_exists('uri-id', $item)) { $html = str_replace($part, $replaced, $html);
$gallery = $gallery . '-' . $item['uri-id']; }
} $html = str_replace('class="body-attach done"', 'class="body-attach"', $html);
} $b['html'] = $html;
$html = $b['html'];
while (preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)) {
if (is_array($matches)) $matches=$matches[0];
$part = $matches[0];
$replaced = str_replace('<a href', '<a data-fancybox="' . $gallery . '" href', $part);
$replaced = str_replace('<div class="body-attach"', '<div class="body-attach done"', $replaced);
$html =str_replace($part, $replaced, $html);
}
$html = str_replace('class="body-attach done"', 'class="body-attach"', $html);
$b['html'] = $html;
} }