Added image grid generation to addVisualAttachments
This commit is contained in:
parent
c7811576cc
commit
d786f225ee
|
@ -3130,18 +3130,56 @@ class Item
|
|||
|
||||
$s = HTML::applyContentFilter($s, $filter_reasons);
|
||||
|
||||
if (count($attachments['visual']) > 1) {
|
||||
// make imgae grid only for multiple images
|
||||
$s = self::cutAttachedImages($s);
|
||||
$grid = self::make_image_grid($item, $attachments);
|
||||
$s .= $grid;
|
||||
}
|
||||
// if (count($attachments['visual']) > 1) {
|
||||
// // make imgae grid only for multiple images
|
||||
// $s = self::cutAttachedImages($s);
|
||||
// $grid = self::make_image_grid($item, $attachments);
|
||||
// $s .= $grid;
|
||||
// }
|
||||
|
||||
$hook_data = ['item' => $item, 'html' => $s];
|
||||
Hook::callAll('prepare_body_final', $hook_data);
|
||||
return $hook_data['html'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $images
|
||||
* @return string
|
||||
* @throws \Friendica\Network\HTTPException\ServiceUnavailableException
|
||||
*/
|
||||
public static function makeImageGrid(array $images): string
|
||||
{
|
||||
$img_tags_landscape = array();
|
||||
$img_tags_portrait = array();
|
||||
foreach ($images as $image) {
|
||||
($image['attachment']['width'] > $image['attachment']['height']) ? ($img_tags_landscape[] = $image) : ($img_tags_portrait[] = $image);
|
||||
}
|
||||
|
||||
// @todo add some fany ai to divide images equally on both columns
|
||||
$img_tags_fc = array();
|
||||
$img_tags_sc = array();
|
||||
if (count($img_tags_landscape) == 0) {
|
||||
// only portrait
|
||||
for ($i = 0; $i < count($img_tags_portrait); $i++) {
|
||||
($i % 2 == 0) ? ($img_tags_fc[] = $img_tags_portrait[$i]) : ($img_tags_sc[] = $img_tags_portrait[$i]);
|
||||
}
|
||||
}
|
||||
if (count($img_tags_portrait) == 0) {
|
||||
// ony landscapes
|
||||
for ($i = 0; $i < count($img_tags_landscape); $i++) {
|
||||
($i % 2 == 0) ? ($img_tags_fc[] = $img_tags_landscape[$i]) : ($img_tags_sc[] = $img_tags_landscape[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image_grid.tpl'), [
|
||||
'columns' => [
|
||||
'fc' => $img_tags_fc,
|
||||
'sc' => $img_tags_sc,
|
||||
],
|
||||
]);
|
||||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function removes images at the very end of a post based on the assumption that this images are interpreted
|
||||
* as attachments
|
||||
|
@ -3396,17 +3434,22 @@ class Item
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($images as $image) {
|
||||
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [
|
||||
'$image' => $image,
|
||||
$media = '';
|
||||
if (count($images) > 1) {
|
||||
$media = self::makeImageGrid($images);
|
||||
}
|
||||
elseif (count($images) == 1) {
|
||||
$media = $media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [
|
||||
'$image' => $images[0],
|
||||
]);
|
||||
}
|
||||
|
||||
// On Diaspora posts the attached pictures are leading
|
||||
if ($item['network'] == Protocol::DIASPORA) {
|
||||
$leading .= $media;
|
||||
} else {
|
||||
$trailing .= $media;
|
||||
}
|
||||
}
|
||||
|
||||
if ($shared) {
|
||||
$content = str_replace(BBCode::TOP_ANCHOR, '<div class="body-attach">' . $leading . '<div class="clear"></div></div>' . BBCode::TOP_ANCHOR, $content);
|
||||
|
|
|
@ -2,17 +2,13 @@
|
|||
|
||||
<div id="row" class="row">
|
||||
<div class="column">
|
||||
{{foreach $columns.fc as $fc}}
|
||||
{{foreach $fc as $img}}
|
||||
{{foreach $columns.fc as $img}}
|
||||
{{include file="content/image.tpl" image=$img}}
|
||||
{{/foreach}}
|
||||
{{/foreach}}
|
||||
</div>
|
||||
<div class="column">
|
||||
{{foreach $columns.sc as $sc}}
|
||||
{{foreach $sc as $img}}
|
||||
{{foreach $columns.sc as $img}}
|
||||
{{include file="content/image.tpl" image=$img}}
|
||||
{{/foreach}}
|
||||
{{/foreach}}
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user