From 9dc2f112abb3c10fa4e927860c19a2e8f97c851c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Sat, 14 Apr 2018 23:53:43 +0200 Subject: [PATCH] Replace getTrueName by the Eloquent attribute --- app/Contact.php | 41 ------------------- app/Roster.php | 2 +- app/widgets/Blog/blog.tpl | 2 +- app/widgets/Chat/Chat.php | 2 +- app/widgets/Chat/_chat_empty.tpl | 2 +- .../CommunityAffiliations.php | 2 + .../_communityaffiliations.tpl | 14 +++---- .../_communityaffiliations_config_content.tpl | 4 +- .../_communityaffiliations_subscriptions.tpl | 4 +- app/widgets/Config/Config.php | 2 + .../ContactActions/_contactactions_add.tpl | 4 +- .../ContactActions/_contactactions_drawer.tpl | 2 +- app/widgets/ContactDisco/_contactdisco.tpl | 2 +- app/widgets/Invitations/_invitations_from.tpl | 2 +- app/widgets/Login/login.tpl | 4 +- app/widgets/Menu/Menu.php | 4 +- app/widgets/Post/_post_comments_external.tpl | 2 +- app/widgets/Presence/_presence.tpl | 2 +- app/widgets/Roster/roster.tpl | 1 + app/widgets/Syndication/Syndication.php | 4 +- app/widgets/Visio/visio.tpl | 2 +- 21 files changed, 34 insertions(+), 70 deletions(-) diff --git a/app/Contact.php b/app/Contact.php index f7e8aaf59..8e18f1ddb 100644 --- a/app/Contact.php +++ b/app/Contact.php @@ -155,47 +155,6 @@ class Contact extends Model return $place; } - public function getTrueName() - { - $truename = ''; - - if (isset($this->rostername)) - $rostername = str_replace('\40', '', $this->rostername); - else - $rostername = ''; - - if ( - isset($this->rostername) - && $rostername != '' - && !filter_var($rostername, FILTER_VALIDATE_EMAIL) - ) - $truename = $rostername; - elseif ( - isset($this->fn) - && $this->fn != '' - && !filter_var($this->fn, FILTER_VALIDATE_EMAIL) - ) - $truename = $this->fn; - elseif ( - isset($this->nickname) - && $this->nickname != '' - && !filter_var($this->nickname, FILTER_VALIDATE_EMAIL) - ) - $truename = $this->nickname; - elseif ( - isset($this->name) - && $this->name != '' - && !filter_var($this->name, FILTER_VALIDATE_EMAIL) - ) - $truename = $this->name; - else { - $truename = explodeJid($this->id); - $truename = $truename['username']; - } - - return $truename; - } - public function getTruenameAttribute() { if ($this->fn) return $this->fn; diff --git a/app/Roster.php b/app/Roster.php index e39d0e2a8..57ad8e593 100644 --- a/app/Roster.php +++ b/app/Roster.php @@ -102,7 +102,7 @@ class Roster extends Model public function getTruenameAttribute() { - if ($this->name) return $this->name; + if ($this->name && !filter_var($this->name, FILTER_VALIDATE_EMAIL)) return $this->name; if ($this->contact && $this->contact->truename) { return $this->contact->truename; } diff --git a/app/widgets/Blog/blog.tpl b/app/widgets/Blog/blog.tpl index 100305592..7f15cb743 100644 --- a/app/widgets/Blog/blog.tpl +++ b/app/widgets/Blog/blog.tpl @@ -17,7 +17,7 @@ {if="$contact"}

- {$c->__('blog.title', $contact->getTrueName())} + {$c->__('blog.title', $contact->truename)}

{if="$contact->description"} diff --git a/app/widgets/Chat/Chat.php b/app/widgets/Chat/Chat.php index dd8124cc3..5c7dda212 100644 --- a/app/widgets/Chat/Chat.php +++ b/app/widgets/Chat/Chat.php @@ -64,7 +64,7 @@ class Chat extends \Movim\Widget\Base $presences = getPresences(); $presence = $presences[$contact->value]; - Notification::append('presence', $contact->getTrueName(), $presence, $avatar, 4); + Notification::append('presence', $contact->truename, $presence, $avatar, 4); } } }*/ diff --git a/app/widgets/Chat/_chat_empty.tpl b/app/widgets/Chat/_chat_empty.tpl index 75cd3a338..3cb87fab9 100644 --- a/app/widgets/Chat/_chat_empty.tpl +++ b/app/widgets/Chat/_chat_empty.tpl @@ -26,7 +26,7 @@ {/if} -

{$value->getTrueName()}

+

{$value->truename}

{$value->jid}

{/loop} diff --git a/app/widgets/CommunityAffiliations/CommunityAffiliations.php b/app/widgets/CommunityAffiliations/CommunityAffiliations.php index ebefe0629..a5f41d4f1 100644 --- a/app/widgets/CommunityAffiliations/CommunityAffiliations.php +++ b/app/widgets/CommunityAffiliations/CommunityAffiliations.php @@ -163,6 +163,8 @@ class CommunityAffiliations extends \Movim\Widget\Base { if (!$this->validateServerNode($origin, $node)) return; + (new CommunityHeader)->ajaxUnsubscribe($origin, $node); + $d = new Delete; $d->setTo($origin)->setNode($node) ->request(); diff --git a/app/widgets/CommunityAffiliations/_communityaffiliations.tpl b/app/widgets/CommunityAffiliations/_communityaffiliations.tpl index 5f135be89..b0a66d254 100644 --- a/app/widgets/CommunityAffiliations/_communityaffiliations.tpl +++ b/app/widgets/CommunityAffiliations/_communityaffiliations.tpl @@ -43,10 +43,10 @@ {else} - {$contact->getTrueName()|firstLetterCapitalize} + {$contact->truename|firstLetterCapitalize} {/if} -

{$contact->getTrueName()}

+

{$contact->truename}

{$contact->jid}

{/loop} @@ -69,17 +69,17 @@ {else} - {$contact->getTrueName()|firstLetterCapitalize} + {$contact->truename|firstLetterCapitalize} {/if} -

{$contact->getTrueName()}

+

{$contact->truename}

{$contact->jid}

{/loop} {/if} -{if="$subscriptions"} +{if="$subscriptions->isNotEmpty()"} diff --git a/app/widgets/ContactDisco/_contactdisco.tpl b/app/widgets/ContactDisco/_contactdisco.tpl index b45446f06..e33980194 100644 --- a/app/widgets/ContactDisco/_contactdisco.tpl +++ b/app/widgets/ContactDisco/_contactdisco.tpl @@ -23,7 +23,7 @@ {/if}

- {$value->getTrueName()} + {$value->truename} {if="!empty($value->description)"} {$value->description|strip_tags|truncate:80} diff --git a/app/widgets/Invitations/_invitations_from.tpl b/app/widgets/Invitations/_invitations_from.tpl index 0cb21d06d..a2412a7b9 100644 --- a/app/widgets/Invitations/_invitations_from.tpl +++ b/app/widgets/Invitations/_invitations_from.tpl @@ -32,7 +32,7 @@

- {$c->__('invitations.wants_to_talk', $value->getTrueName())} + {$c->__('invitations.wants_to_talk', $value->truename)}

{$value->jid}

diff --git a/app/widgets/Login/login.tpl b/app/widgets/Login/login.tpl index 54fb66e6c..d5c000bbb 100644 --- a/app/widgets/Login/login.tpl +++ b/app/widgets/Login/login.tpl @@ -31,11 +31,11 @@ {else} - {$contact->getTrueName()|firstLetterCapitalize} + {$contact->truename|firstLetterCapitalize} {/if}

-

{$c->__('form.invite_chatroom', $contact->getTrueName())} - {$invitation->resource}

+

{$c->__('form.invite_chatroom', $contact->truename)} - {$invitation->resource}

{/if} diff --git a/app/widgets/Menu/Menu.php b/app/widgets/Menu/Menu.php index 458d8f801..e5b99015e 100644 --- a/app/widgets/Menu/Menu.php +++ b/app/widgets/Menu/Menu.php @@ -59,7 +59,7 @@ class Menu extends \Movim\Widget\Base $contact = \App\Contact::firstOrNew(['id' => $post->aid]); Notification::append( 'news', - $contact->getTrueName(), + $contact->truename, $post->title, $contact->getPhoto('s'), 2 @@ -76,7 +76,7 @@ class Menu extends \Movim\Widget\Base if (!$post->isMine()) { Notification::append( 'news', - $contact->getTrueName(), + $contact->truename, $title, $contact->getPhoto('s'), 2, diff --git a/app/widgets/Post/_post_comments_external.tpl b/app/widgets/Post/_post_comments_external.tpl index 65efe28b4..88ba2e558 100644 --- a/app/widgets/Post/_post_comments_external.tpl +++ b/app/widgets/Post/_post_comments_external.tpl @@ -29,7 +29,7 @@ {$value->published|strtotime|prepareDate:true,true} - {$value->getContact()->getTrueName()} + {$value->getContact()->truename}

{if="!$value->isLike()"}

diff --git a/app/widgets/Presence/_presence.tpl b/app/widgets/Presence/_presence.tpl index b42cc2e58..cebb5b12d 100644 --- a/app/widgets/Presence/_presence.tpl +++ b/app/widgets/Presence/_presence.tpl @@ -19,6 +19,6 @@

- {$me->getTrueName()} + {$me->truename}

diff --git a/app/widgets/Roster/roster.tpl b/app/widgets/Roster/roster.tpl index 03ed2fb28..d0a339085 100644 --- a/app/widgets/Roster/roster.tpl +++ b/app/widgets/Roster/roster.tpl @@ -1,3 +1,4 @@
{$c->prepareItems()}
+
diff --git a/app/widgets/Syndication/Syndication.php b/app/widgets/Syndication/Syndication.php index 3bb63c7b1..0db3b541a 100644 --- a/app/widgets/Syndication/Syndication.php +++ b/app/widgets/Syndication/Syndication.php @@ -48,10 +48,10 @@ class Syndication extends \Movim\Widget\Base $alternate->setAttribute('rel', 'alternate'); if ($contact != null) { - $feed->appendChild($dom->createElement('title', __('feed.title', $contact->getTrueName()))); + $feed->appendChild($dom->createElement('title', __('feed.title', $contact->truename))); $feed->appendChild($author = $dom->createElement('author')); - $author->appendChild($dom->createElement('name', $contact->getTrueName())); + $author->appendChild($dom->createElement('name', $contact->truename)); $author->appendChild($dom->createElement('uri', $this->route('blog', $from))); $feed->appendChild($dom->createElement('logo', $contact->getPhoto('l'))); diff --git a/app/widgets/Visio/visio.tpl b/app/widgets/Visio/visio.tpl index 583475b1a..f669a026c 100644 --- a/app/widgets/Visio/visio.tpl +++ b/app/widgets/Visio/visio.tpl @@ -25,7 +25,7 @@ {/if}

- {$contact->getTrueName()} + {$contact->truename}