@@ 19-63 (lines=45) @@ | ||
16 | * |
|
17 | * @author Morrison Laju <[email protected]> |
|
18 | */ |
|
19 | class LinkedIn implements ProviderInterface |
|
20 | { |
|
21 | const NAME = 'linkedin'; |
|
22 | const SHARE_URL = 'https://www.linkedin.com/shareArticle?%s'; |
|
23 | const API_URL = 'https://www.linkedin.com/countserv/count/share?url=%s&format=json'; |
|
24 | ||
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | public function getName() |
|
29 | { |
|
30 | return self::NAME; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Gets the share link for the URL. |
|
35 | * |
|
36 | * @param array $options This provider supports the following options:<pre> |
|
37 | * title: the title |
|
38 | * summary: the summary |
|
39 | * source: the source |
|
40 | * </pre> |
|
41 | * @param string $url |
|
42 | * @param array $options |
|
43 | * |
|
44 | * @return string |
|
45 | */ |
|
46 | public function getLink($url, array $options = array()) |
|
47 | { |
|
48 | $options['mini'] = 'true'; |
|
49 | $options['url'] = $url; |
|
50 | ||
51 | return sprintf(self::SHARE_URL, http_build_query($options, null, '&')); |
|
52 | } |
|
53 | ||
54 | /** |
|
55 | * {@inheritdoc} |
|
56 | */ |
|
57 | public function getShares($url) |
|
58 | { |
|
59 | $data = json_decode(file_get_contents(sprintf(self::API_URL, urlencode($url)))); |
|
60 | ||
61 | return intval($data->count); |
|
62 | } |
|
63 | } |
|
64 |
@@ 19-52 (lines=34) @@ | ||
16 | * |
|
17 | * @author Kévin Dunglas <[email protected]> |
|
18 | */ |
|
19 | class Pinterest implements ProviderInterface |
|
20 | { |
|
21 | const NAME = 'pinterest'; |
|
22 | const SHARE_URL = 'https://www.pinterest.com/pin/create/link/?%s'; |
|
23 | const API_URL = 'https://api.pinterest.com/v1/urls/count.json?url=%s'; |
|
24 | ||
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | public function getName() |
|
29 | { |
|
30 | return self::NAME; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * {@inheritdoc} |
|
35 | */ |
|
36 | public function getLink($url, array $options = array()) |
|
37 | { |
|
38 | $options['url'] = $url; |
|
39 | ||
40 | return sprintf(self::SHARE_URL, http_build_query($options, null, '&')); |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * {@inheritdoc} |
|
45 | */ |
|
46 | public function getShares($url) |
|
47 | { |
|
48 | $data = json_decode(preg_replace('/^receiveCount\((.*)\)$/', '\\1', file_get_contents(sprintf(self::API_URL, urlencode($url))))); |
|
49 | ||
50 | return intval($data->count); |
|
51 | } |
|
52 | } |
|
53 |
@@ 19-52 (lines=34) @@ | ||
16 | * |
|
17 | * @author Kévin Dunglas <[email protected]> |
|
18 | */ |
|
19 | class Twitter implements ProviderInterface |
|
20 | { |
|
21 | const NAME = 'twitter'; |
|
22 | const SHARE_URL = 'https://twitter.com/intent/tweet?%s'; |
|
23 | const API_URL = 'https://cdn.api.twitter.com/1/urls/count.json?url=%s'; |
|
24 | ||
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | public function getName() |
|
29 | { |
|
30 | return self::NAME; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * {@inheritdoc} |
|
35 | */ |
|
36 | public function getLink($url, array $options = array()) |
|
37 | { |
|
38 | $options['url'] = $url; |
|
39 | ||
40 | return sprintf(self::SHARE_URL, http_build_query($options, null, '&')); |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * {@inheritdoc} |
|
45 | */ |
|
46 | public function getShares($url) |
|
47 | { |
|
48 | $data = json_decode(file_get_contents(sprintf(self::API_URL, urlencode($url)))); |
|
49 | ||
50 | return intval($data->count); |
|
51 | } |
|
52 | } |
|
53 |