Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add xing to social sync #1869

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions css/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@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)
@include icon-black-white('xing', 'contacts', 2); // “xing (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/xing?style=brands)

.icon-up-force-white {
// using #fffffe to trick the accessibility dark theme icon invert
Expand Down
1 change: 1 addition & 0 deletions img/license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* “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)
* “xing (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/xing?style=brands)
1 change: 1 addition & 0 deletions img/xing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion lib/Service/Social/CompositeSocialProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function __construct(InstagramProvider $instagramProvider,
FacebookProvider $facebookProvider,
TwitterProvider $twitterProvider,
TumblrProvider $tumblrProvider,
DiasporaProvider $diasporaProvider) {
DiasporaProvider $diasporaProvider,
XingProvider $xingProvider) {

// This determines the priority of known providers
$this->providers = [
Expand All @@ -46,6 +47,7 @@ public function __construct(InstagramProvider $instagramProvider,
'facebook' => $facebookProvider,
'tumblr' => $tumblrProvider,
'diaspora' => $diasporaProvider,
'xing' => $xingProvider,
];
}

Expand Down
82 changes: 82 additions & 0 deletions lib/Service/Social/XingProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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 XingProvider 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 {
$candidate = preg_replace('/^' . preg_quote('x-apple:', '/') . '/', '', $candidate);
try {
if (strpos($candidate, 'http') !== 0) {
$candidate = 'https://www.xing.com/profile/' . $candidate;
}
} 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 = '/.*src="(https:\/\/profile-images[a-zA-Z0-9\/.\-_]+\.jpg)".*/';
if (preg_match($avatar, $htmlResult, $matches)) {
return $matches[1];
}
// keyword not found, maybe page changed?
return null;
} catch (Exception $e) {
return null;
}
}
}