Browse Source

Enforce at least one picture to be attached when the Community is a gallery

pull/1171/head
Timothée Jaussoin 3 years ago
parent
commit
70460b551d
  1. 2
      app/helpers/UtilsHelper.php
  2. 4
      app/widgets/CommunityHeader/_communityheader.tpl
  3. 5
      app/widgets/CommunitySubscriptions/_communitysubscriptions.tpl
  4. 19
      app/widgets/Post/_post_ticket.tpl
  5. 14
      app/widgets/Publish/Publish.php
  6. 1
      app/widgets/Publish/locales.ini

2
app/helpers/UtilsHelper.php

@ -190,7 +190,7 @@ function resolveInfos($postCollection)
/**
* Return a picture with a specific size
*/
function getPhoto(string $key, string $size = 'm')
function getPhoto(string $key, string $size = 'm'): ?string
{
$sizes = [
'xxl' => [1280, 300],

4
app/widgets/CommunityHeader/_communityheader.tpl

@ -1,12 +1,12 @@
{if="$info != null && $info->pubsubpublishmodel != null && $info->pubsubpublishmodel != 'publishers'"}
{if="$info->pubsubpublishmodel == 'open' || ($info->pubsubpublishmodel == 'subscribers' && $subscription != null)"}
<a class="button action color" title="{$c->__('menu.add_post')}" href="{$c->route('publish', [$server, $node])}">
<i class="material-icons">post_add</i>
<i class="material-icons">{if="$info->isGallery()"}add_photo_alternate{else}post_add{/if}</i>
</a>
{/if}
{else}
<a onclick="CommunityHeader_ajaxTestPublish('{$server}', '{$node}')" class="button action color" title="{$c->__('menu.add_post')}">
<i class="material-icons">post_add</i>
<i class="material-icons">{if="$info!= null && $info->isGallery()"}add_photo_alternate{else}post_add{/if}</i>
</a>
{/if}
<ul class="list thick">

5
app/widgets/CommunitySubscriptions/_communitysubscriptions.tpl

@ -53,6 +53,11 @@
{if="$value->public"}
<span class="tag color gray">{$c->__('room.public_muc')}</span>
{/if}
{if="$value->info && $value->info->isGallery()"}
<i class="material-icons">grid_view</i>
{$c->__('communityconfig.type_gallery_title')}
·
{/if}
{if="$value->info && $value->info->description"}
{$value->info->description|strip_tags}
{else}

19
app/widgets/Post/_post_ticket.tpl

@ -18,20 +18,6 @@
style="background-image: url({$post->picture->href|protectPicture});"
>
</span>
{elseif="!$post->contact"}
<span class="control icon bubble color {$post->node|stringToColor}"
{$url = false}
{if="$post->info"}
{$url = $post->info->getPhoto('m')}
{/if}
{if="$url"}
style="background-image: url({$url});"
{/if}
>
{if="$url == false"}
{$post->node|firstLetterCapitalize}
{/if}
</span>
{/if}
<div>
<p class="line two" {if="isset($post->title)"}title="{$post->title}"{/if}>
@ -70,6 +56,11 @@
{/if}
<span class="info" title="{$post->published|strtotime|prepareDate}">
{$count = $post->pictures->count()}
{if="$count > 0"}
{$count} <i class="material-icons">collections</i> ·
{/if}
{$count = $post->likes->count()}
{if="$count > 0"}
{$count} <i class="material-icons">favorite_border</i> ·

14
app/widgets/Publish/Publish.php

@ -209,12 +209,16 @@ class Publish extends Base
$p->setReply($post->getRef());
}
$hasImage = false;
foreach ($draft->embeds as $embed) {
$resolved = $embed->resolve();
// The url is an image
if ($resolved->type == 'image'
&& $resolved->images[0]['url'] == $embed->url) {
if (!$hasImage) $hasImage = true;
$p->addImage(
$resolved->images[0]['url'],
$resolved->title,
@ -254,6 +258,16 @@ class Publish extends Base
}
}
$info = \App\Info::where('server', $draft->server)
->where('node', $draft->node)
->first();
if ($info && $info->isGallery() && !$hasImage) {
$this->rpc('Publish.enableSend');
Toast::send($this->__('publish.no_picture'));
return;
}
$p->request();
$draft->delete();
} else {

1
app/widgets/Publish/locales.ini

@ -4,6 +4,7 @@ post = Write a post
add_link = Add a link
add_snap = Take a picture
no_title = Please provide a title
no_picture = At least one picture is required
preview = Preview
attach = Add a file or a picture
no_publication = You cannot publish a post here

Loading…
Cancel
Save