From b69e8f8e0205b4b145ae0cc4e6b0c13271153ee5 Mon Sep 17 00:00:00 2001 From: Panos Date: Tue, 9 Feb 2016 17:03:16 +0100 Subject: [PATCH] Fixed bug with new Twitter policy. Added messages on share buttons --- Library/SocialShare/Networks/Facebook.php | 9 +++++++-- Library/SocialShare/Networks/LinkedIn.php | 9 +++++++-- Library/SocialShare/Networks/Twitter.php | 9 +++++++-- Resources/translations/icap_socialmedia.en.yml | 7 ++++++- Resources/translations/icap_socialmedia.fr.yml | 7 ++++++- Resources/views/ShareAction/form.html.twig | 4 ++-- VERSION.txt | 2 +- 7 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Library/SocialShare/Networks/Facebook.php b/Library/SocialShare/Networks/Facebook.php index b89933d..bae919f 100644 --- a/Library/SocialShare/Networks/Facebook.php +++ b/Library/SocialShare/Networks/Facebook.php @@ -51,9 +51,14 @@ public function getShareLink($url, array $options = array()) public function countShares($url) { $api_url = sprintf(self::API_URL, urlencode($url)); - $data = json_decode(file_get_contents($api_url)); + $data = null; + try{ + $data = json_decode(file_get_contents($api_url)); + } catch(\Exception $e) { + $data = null; + } - return isset($data[0]->share_count)?intval($data[0]->share_count):0; + return ($data !== null && isset($data[0]->share_count))?intval($data[0]->share_count):0; } /** diff --git a/Library/SocialShare/Networks/LinkedIn.php b/Library/SocialShare/Networks/LinkedIn.php index 586ef1d..7d46db2 100644 --- a/Library/SocialShare/Networks/LinkedIn.php +++ b/Library/SocialShare/Networks/LinkedIn.php @@ -54,9 +54,14 @@ public function getShareLink($url, array $options = array()) public function countShares($url) { $api_url = sprintf(self::API_URL, urlencode($url)); - $data = json_decode(file_get_contents($api_url)); + $data = null; + try{ + $data = json_decode(file_get_contents($api_url)); + } catch(\Exception $e) { + $data = null; + } - return isset($data->count)?intval($data->count):0; + return ($data !== null && isset($data->count))?intval($data->count):0; } /** diff --git a/Library/SocialShare/Networks/Twitter.php b/Library/SocialShare/Networks/Twitter.php index 9194bb4..4153b6e 100644 --- a/Library/SocialShare/Networks/Twitter.php +++ b/Library/SocialShare/Networks/Twitter.php @@ -53,9 +53,14 @@ public function getShareLink($url, array $options = array()) public function countShares($url) { $api_url = sprintf(self::API_URL, urlencode($url)); - $data = json_decode(file_get_contents($api_url)); + $data = null; + try{ + $data = json_decode(file_get_contents($api_url)); + } catch(\Exception $e) { + $data = null; + } - return isset($data->count)?intval($data->count):0; + return ($data !== null && isset($data->count))?intval($data->count):0; } /** diff --git a/Resources/translations/icap_socialmedia.en.yml b/Resources/translations/icap_socialmedia.en.yml index ff281da..347afb4 100644 --- a/Resources/translations/icap_socialmedia.en.yml +++ b/Resources/translations/icap_socialmedia.en.yml @@ -21,4 +21,9 @@ load_next_notes: View more reminders load_next_likes: View more likes load_next_wall_items: View more items comments_are_public: Comments are public -notes_are_private: Remiders are personal \ No newline at end of file +notes_are_private: Remiders are personal +platform_share_message: Shares number on platform +facebook_share_message: Shares on Facebook +twitter_share_message: Shares on Twitter are not available due to its new policy +google_share_message: Shares on Google+ +linkedin_share_message: Shares on LinkedIn \ No newline at end of file diff --git a/Resources/translations/icap_socialmedia.fr.yml b/Resources/translations/icap_socialmedia.fr.yml index 94e30b3..81471ff 100644 --- a/Resources/translations/icap_socialmedia.fr.yml +++ b/Resources/translations/icap_socialmedia.fr.yml @@ -21,4 +21,9 @@ load_next_notes: Voir les pense-bêtes suivants load_next_likes: Voir les suivants load_next_wall_items: Voir les éléments suivants comments_are_public: Tous les commentaires sont publics -notes_are_private: Tous les pense-bêtes sont privés \ No newline at end of file +notes_are_private: Tous les pense-bêtes sont privés +platform_share_message: Nombre de partages sur la plateforme +facebook_share_message: Nombre de partages sur Facebook +twitter_share_message: Nombre de partages sur Twitter indisponible à cause de la nouvelle politique du site de twitter +google_share_message: Nombre de partages sur Google+ +linkedin_share_message: Nombre de partages sur LinkedIn \ No newline at end of file diff --git a/Resources/views/ShareAction/form.html.twig b/Resources/views/ShareAction/form.html.twig index 15c78b9..e7a520a 100644 --- a/Resources/views/ShareAction/form.html.twig +++ b/Resources/views/ShareAction/form.html.twig @@ -7,9 +7,9 @@