Skip to content

Commit

Permalink
added support for mastodon social media platform and refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijitb committed Feb 8, 2023
1 parent b601258 commit 43ebccd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions includes/RestApi/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SettingsController {
'youtube_url' => '',
'wikipedia_url' => '',
'other_social_urls' => array(),
'mastodon_url' => '',
);

/**
Expand All @@ -69,6 +70,7 @@ class SettingsController {
'youtube_url',
'wikipedia_url',
'other_social_urls',
'mastodon_url',
);

/**
Expand Down Expand Up @@ -215,24 +217,23 @@ public function get_current_settings() {
$social_data['twitter_site'] = 'https://www.twitter.com/' . $twitter_handle;
}

$filtered_social_urls = array();
// handle other social urls for onboarding
foreach ( $social_data['other_social_urls'] as $index => $social_url ) {
// remove the indexed url from array
unset( $social_data['other_social_urls'][ $index ] );

switch ( $social_url ) {
case ( preg_match( '/(?:https?:\/\/)?(www\.)?yelp\.com\//', $social_url ) ? true : false ):
$social_data['other_social_urls']['yelp_url'] = $social_url;
case ( preg_match( '/(?:https?:\/\/)?(www\.)?yelp\.com/', $social_url ) ? true : false ):
$filtered_social_urls['yelp_url'] = $social_url;
break;
case ( preg_match( '/(?:https?:\/\/)?(www\.)?tiktok\.com\//', $social_url ) ? true : false ):
$social_data['other_social_urls']['tiktok_url'] = $social_url;
case ( preg_match( '/(?:https?:\/\/)?(www\.)?tiktok\.com/', $social_url ) ? true : false ):
$filtered_social_urls['tiktok_url'] = $social_url;
break;
default:
// creating key value pairs for other social urls instead of indexed array
$social_data['other_social_urls'][ 'social_url_' . $index ] = $social_url;
$filtered_social_urls[ 'social_url_' . $index ] = $social_url;
break;
}
}
$social_data['other_social_urls'] = $filtered_social_urls;
return $social_data;

}
Expand Down

0 comments on commit 43ebccd

Please sign in to comment.