diff options
author | call-me-matt <nextcloud@matthiasheinisch.de> | 2020-10-15 11:30:18 +0200 |
---|---|---|
committer | call-me-matt <nextcloud@matthiasheinisch.de> | 2020-10-15 11:42:54 +0200 |
commit | 5e6f65a9f000aaea7ac28d07f2892f7107e87934 (patch) | |
tree | a241e3e675ff1ef6626a7d2d7b4fbda2a109c6e6 | |
parent | 1dcbafc16cfc175ea68c32f604566172b0b48eba (diff) |
adding diaspora to the list for social sync
Signed-off-by: call-me-matt <nextcloud@matthiasheinisch.de>
-rw-r--r-- | css/icons.scss | 1 | ||||
-rw-r--r-- | img/diaspora.svg | 1 | ||||
-rw-r--r-- | img/license.txt | 1 | ||||
-rw-r--r-- | lib/Service/Social/CompositeSocialProvider.php | 4 | ||||
-rw-r--r-- | lib/Service/Social/DiasporaProvider.php | 89 |
5 files changed, 95 insertions, 1 deletions
diff --git a/css/icons.scss b/css/icons.scss index 14889d61..1516587f 100644 --- a/css/icons.scss +++ b/css/icons.scss @@ -39,6 +39,7 @@ @include icon-black-white('mastodon', 'contacts', 2); // “mastodon (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/mastodon?style=brands) @include icon-black-white('tumblr', 'contacts', 2); // “tumblr (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/tumblr?style=brands) @include icon-black-white('twitter', 'contacts', 2); // “twitter (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/twitter?style=brands) +@include icon-black-white('diaspora', 'contacts', 2); // “diaspora (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/diaspora?style=brands) .icon-up-force-white { // using #fffffe to trick the accessibility dark theme icon invert diff --git a/img/diaspora.svg b/img/diaspora.svg new file mode 100644 index 00000000..6e5b75fa --- /dev/null +++ b/img/diaspora.svg @@ -0,0 +1 @@ +<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="diaspora" class="svg-inline--fa fa-diaspora fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M251.64 354.55c-1.4 0-88 119.9-88.7 119.9S76.34 414 76 413.25s86.6-125.7 86.6-127.4c0-2.2-129.6-44-137.6-47.1-1.3-.5 31.4-101.8 31.7-102.1.6-.7 144.4 47 145.5 47 .4 0 .9-.6 1-1.3.4-2 1-148.6 1.7-149.6.8-1.2 104.5-.7 105.1-.3 1.5 1 3.5 156.1 6.1 156.1 1.4 0 138.7-47 139.3-46.3.8.9 31.9 102.2 31.5 102.6-.9.9-140.2 47.1-140.6 48.8-.3 1.4 82.8 122.1 82.5 122.9s-85.5 63.5-86.3 63.5c-1-.2-89-125.5-90.9-125.5z"></path></svg>
\ No newline at end of file diff --git a/img/license.txt b/img/license.txt index d4e74fdb..8ce24f73 100644 --- a/img/license.txt +++ b/img/license.txt @@ -4,3 +4,4 @@ * “mastodon (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/mastodon?style=brands) * “tumblr (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/tumblr?style=brands) * “twitter (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/twitter?style=brands) +* “diaspora (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/diaspora?style=brands) diff --git a/lib/Service/Social/CompositeSocialProvider.php b/lib/Service/Social/CompositeSocialProvider.php index a5f6e484..bca9939d 100644 --- a/lib/Service/Social/CompositeSocialProvider.php +++ b/lib/Service/Social/CompositeSocialProvider.php @@ -35,7 +35,8 @@ class CompositeSocialProvider { MastodonProvider $mastodonProvider, FacebookProvider $facebookProvider, TwitterProvider $twitterProvider, - TumblrProvider $tumblrProvider) { + TumblrProvider $tumblrProvider, + DiasporaProvider $diasporaProvider) { // This determines the priority of known providers $this->providers = [ @@ -44,6 +45,7 @@ class CompositeSocialProvider { 'twitter' => $twitterProvider, 'facebook' => $facebookProvider, 'tumblr' => $tumblrProvider, + 'diaspora' => $diasporaProvider, ]; } diff --git a/lib/Service/Social/DiasporaProvider.php b/lib/Service/Social/DiasporaProvider.php new file mode 100644 index 00000000..73f85792 --- /dev/null +++ b/lib/Service/Social/DiasporaProvider.php @@ -0,0 +1,89 @@ +<?php +/** + * @copyright Copyright (c) 2020 Matthias Heinisch <nextcloud@matthiasheinisch.de> + * + * @author Matthias Heinisch <nextcloud@matthiasheinisch.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Contacts\Service\Social; + +use OCP\Http\Client\IClientService; + +class DiasporaProvider implements ISocialProvider { + + /** @var IClientService */ + private $httpClient; + + /** @var boolean */ + private $looping; + + public function __construct(IClientService $httpClient) { + $this->httpClient = $httpClient->NewClient(); + $this->looping = false; + } + + /** + * Returns the profile-id + * + * @param {string} the value from the contact's x-socialprofile + * + * @return string + */ + public function cleanupId(string $candidate):string { + try { + if (strpos($candidate, 'http') !== 0) { + $user_server = explode('@', $candidate); + $candidate = 'https://' . array_pop($user_server) . '/public/' . array_pop($user_server) . '.atom'; + } + } catch (Exception $e) { + $candidate = null; + } + return $candidate; + } + + /** + * Returns the profile-picture url + * + * @param {string} profileId the profile-id + * + * @return string|null + */ + public function getImageUrl(string $profileUrl):?string { + try { + $result = $this->httpClient->get($profileUrl); + $htmlResult = $result->getBody(); + + $avatar = '/.*<logo>(.*)<\/logo>.*/'; + if (preg_match($avatar, $htmlResult, $matches)) { + return (str_replace("small", "large", $matches[1])); + } + // keyword not found, second try: + if (!$this->looping) { + $this->looping = true; + $atom = '/.*<link rel="alternate" href="(.*.atom)".*/'; + if (preg_match($atom, $htmlResult, $matches)) { + return ($this->getImageUrl($matches[1])); + } + } + return null; + } catch (Exception $e) { + return null; + } + } +} |